/*input
5 6
><>><
2 4
3 5
1 5
1 3
2 4
1 5
*/

// Nihesh Anderson - knandy

#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;

typedef long long ll;
typedef long double ld;
typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> ordered_set; // find_by_order, order_of_key
ll MOD=1000000007;

#define endl '\n'
#define fast_cin() ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define pb push_back
ll INF = 2000000000000000001;
long double EPS = 1e-9;
ll power(ll a, ll n, ll md){if(n==0){return 1;}else{int res=power(a,n/2,md);res=(res*res)%md;if(n%2!=0){res=(res*a)%md;}return res;}}
random_device rndm;
mt19937 grndm(rndm());
void mix(int* a, int* b){shuffle(a,b,grndm);}

template<typename T, typename U> struct seg_tree_lazy {
    int S, H;

    T zero;
    vector<T> value;

    U noop;
    vector<bool> dirty;
    vector<U> prop;

    seg_tree_lazy<T, U>(int _S, T _zero = T(), U _noop = U()) {
        zero = _zero, noop = _noop;
        for (S = 1, H = 1; S < _S; ) S *= 2, H++;

        value.resize(2*S, zero);
        dirty.resize(2*S, false);
        prop.resize(2*S, noop);
    }

    void set_leaves(vector<T> &leaves) {
        copy(leaves.begin(), leaves.end(), value.begin() + S);

        for (int i = S - 1; i > 0; i--)
            value[i] = value[2 * i] + value[2 * i + 1];
    }

    void apply(int i, U &update) {
        value[i] = update(value[i]);
        if(i < S) {
            prop[i] = prop[i] + update;
            dirty[i] = true;
        }
    }

    void rebuild(int i) {
        for (int l = i/2; l; l /= 2) {
            T combined = value[2*l] + value[2*l+1];
            value[l] = prop[l](combined);
        }
    }

    void propagate(int i) {
        for (int h = H; h > 0; h--) {
            int l = i >> h;

            if (dirty[l]) {
                apply(2*l, prop[l]);
                apply(2*l+1, prop[l]);

                prop[l] = noop;
                dirty[l] = false;
            }
        }
    }

    void upd(int i, int j, U update) {
        i += S, j += S;
        propagate(i), propagate(j);

        for (int l = i, r = j; l <= r; l /= 2, r /= 2) {
            if((l&1) == 1) apply(l++, update);
            if((r&1) == 0) apply(r--, update);
        }

        rebuild(i), rebuild(j);
    }

    T query(int i, int j){
        i += S, j += S;
        propagate(i), propagate(j);

        T res_left = zero, res_right = zero;
        for(; i <= j; i /= 2, j /= 2){
            if((i&1) == 1) res_left = res_left + value[i++];
            if((j&1) == 0) res_right = value[j--] + res_right;
        }
        return res_left + res_right;
    }
};

struct node {
	int width, mid[2], left[2][2], right[2][2], left_struct[2], right_struct[2];
	node operator+ (node n) {
		node comb;
		comb.width = width + n.width;

		// fill left and right half of combined
		for(int i = 0; i < 2; i++) {
			for(int j = 0; j < 2; j++) {
				comb.left[i][j] = left[i][j];
				comb.right[i][j] = n.right[i][j];
			}
			comb.left_struct[i] = left_struct[i];
			comb.right_struct[i] = n.right_struct[i];
		}

		for(int i = 0; i < 2; i++) {
			for(int j = 0; j < 2; j++) {
				if(left[i][j] == width) {
					comb.left[i][j] = width + n.left[i][j];
				}
				if(n.right[i][j] == n.width) {
					comb.right[i][j] = n.width + right[i][j];
				}
			}
		}

		for(int i = 0; i < 2; i++) {
			if(left_struct[i] == width) {
				comb.left_struct[i] = width + n.left[i][0];
			}
			if(n.right_struct[i] == n.width) {
				comb.right_struct[i] = n.width + right[i][1];
			}
			if(left[i][1] == width) {
				comb.left_struct[i] = width + n.left_struct[i];
			}
			if(n.right[i][0] == n.width) {
				comb.right_struct[i] = n.width + right_struct[i];
			}
			if(comb.left_struct[i] == comb.width) {
				comb.right_struct[i] = comb.width;
			}
			if(comb.right_struct[i] == comb.width) {
				comb.left_struct[i] = comb.width;
			}
		}

		int center[2];
		for(int i = 0; i < 2; i++) {
			center[i] = right[i][1] + n.left[i][0];
			comb.mid[i] = max({center[i], mid[i], n.mid[i]});
		}
		for(int i = 0; i < 2; i++) {
			for(int j = 0; j < 2; j++) {
				comb.mid[i] = max(comb.mid[i], comb.left[i][j]);
				comb.mid[i] = max(comb.mid[i], comb.right[i][j]);
			}
		}
		for(int i = 0; i < 2; i++) {
			comb.mid[i] = max(comb.mid[i], comb.left_struct[i]);
			comb.mid[i] = max(comb.mid[i], comb.right_struct[i]);
		}
		for(int i = 0; i < 2; i++) {
			comb.mid[i] = max(comb.mid[i], right_struct[i] + n.left[i][0]);
			comb.mid[i] = max(comb.mid[i], n.left_struct[i] + right[i][1]);
		}

		return comb;
	}
};

struct update {
	int val;
	node operator() (node n) {
		if(val) {
			swap(n.mid[0], n.mid[1]);
			for(int i = 0; i < 2; i++) {
				swap(n.left[0][i], n.left[1][i]);
				swap(n.right[0][i], n.right[1][i]);
			}
			swap(n.left_struct[0], n.left_struct[1]);
			swap(n.right_struct[0], n.right_struct[1]);
		}
		return n;
	}
	update operator+ (update u) {
		return {(val + u.val) & 1};
	}
};

int main(){
	fast_cin();
	// freopen("input.in","r",stdin);
	// freopen("output.out","w",stdout);
	int n, q; cin >> n >> q;
	string s; cin >> s;
	node empty;
	empty.width = 0;
	for(int i = 0; i < 2; i++) {
		empty.mid[i] = 0;
		empty.left_struct[i] = empty.right_struct[i] = 0;
		for(int j = 0; j < 2; j++) {
			empty.left[i][j] = 0;
			empty.right[i][j] = 0;
		}
	}
	seg_tree_lazy<node, update> st(n, empty, {0});
	vector<node> leaves;
	for(int t = 0; t < n; t++) {
		node now;
		now.width = 1;
		for(int i = 0; i < 2; i++) {
			now.mid[i] = 1;
			now.left_struct[i] = 1;
			now.right_struct[i] = 1;
			for(int j = 0; j < 2; j++) {
				now.left[i][j] = 0;
				now.right[i][j] = 0;
			}
		}
		if(s[t] == '<') {
			now.left[0][0] = now.right[0][0] = 1;
			now.left[1][1] = now.right[1][1] = 1;
		}
		else {
			now.left[0][1] = now.right[0][1] = 1;
			now.left[1][0] = now.right[1][0] = 1;
		}
		leaves.push_back(now);
	}
	st.set_leaves(leaves);
	while(q--) {
		int l, r; cin >> l >> r;
		l--; r--;
		st.upd(l, r, {1});
		cout << st.query(l, r).mid[0] << endl;
	}
	return 0;
}


/*input
5 6
><>><
2 4
3 5
1 5
1 3
2 4
1 5
*/

// Nihesh Anderson - knandy

#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;

typedef long long ll;
typedef long double ld;
typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> ordered_set; // find_by_order, order_of_key
ll MOD=1000000007;

#define endl '\n'
#define fast_cin() ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define pb push_back
ll INF = 2000000000000000001;
long double EPS = 1e-9;
ll power(ll a, ll n, ll md){if(n==0){return 1;}else{int res=power(a,n/2,md);res=(res*res)%md;if(n%2!=0){res=(res*a)%md;}return res;}}
random_device rndm;
mt19937 grndm(rndm());
void mix(int* a, int* b){shuffle(a,b,grndm);}

template<typename T, typename U> struct seg_tree_lazy {
    int S, H;

    T zero;
    vector<T> value;

    U noop;
    vector<bool> dirty;
    vector<U> prop;

    seg_tree_lazy<T, U>(int _S, T _zero = T(), U _noop = U()) {
        zero = _zero, noop = _noop;
        for (S = 1, H = 1; S < _S; ) S *= 2, H++;

        value.resize(2*S, zero);
        dirty.resize(2*S, false);
        prop.resize(2*S, noop);
    }

    void set_leaves(vector<T> &leaves) {
        copy(leaves.begin(), leaves.end(), value.begin() + S);

        for (int i = S - 1; i > 0; i--)
            value[i] = value[2 * i] + value[2 * i + 1];
    }

    void apply(int i, U &update) {
        value[i] = update(value[i]);
        if(i < S) {
            prop[i] = prop[i] + update;
            dirty[i] = true;
        }
    }

    void rebuild(int i) {
        for (int l = i/2; l; l /= 2) {
            T combined = value[2*l] + value[2*l+1];
            value[l] = prop[l](combined);
        }
    }

    void propagate(int i) {
        for (int h = H; h > 0; h--) {
            int l = i >> h;

            if (dirty[l]) {
                apply(2*l, prop[l]);
                apply(2*l+1, prop[l]);

                prop[l] = noop;
                dirty[l] = false;
            }
        }
    }

    void upd(int i, int j, U update) {
        i += S, j += S;
        propagate(i), propagate(j);

        for (int l = i, r = j; l <= r; l /= 2, r /= 2) {
            if((l&1) == 1) apply(l++, update);
            if((r&1) == 0) apply(r--, update);
        }

        rebuild(i), rebuild(j);
    }

    T query(int i, int j){
        i += S, j += S;
        propagate(i), propagate(j);

        T res_left = zero, res_right = zero;
        for(; i <= j; i /= 2, j /= 2){
            if((i&1) == 1) res_left = res_left + value[i++];
            if((j&1) == 0) res_right = value[j--] + res_right;
        }
        return res_left + res_right;
    }
};

struct node {
	int width, mid[2], left[2][2], right[2][2], left_struct[2], right_struct[2];
	node operator+ (node n) {
		node comb;
		comb.width = width + n.width;

		// fill left and right half of combined
		for(int i = 0; i < 2; i++) {
			for(int j = 0; j < 2; j++) {
				comb.left[i][j] = left[i][j];
				comb.right[i][j] = n.right[i][j];
			}
			comb.left_struct[i] = left_struct[i];
			comb.right_struct[i] = n.right_struct[i];
		}

		for(int i = 0; i < 2; i++) {
			if(left_struct[i] == width) {
				comb.left_struct[i] = width + n.left[i][0];
			}
			if(n.right_struct[i] == n.width) {
				comb.right_struct[i] = n.width + right[i][1];
			}
			if(comb.left_struct[i] == comb.width) {
				comb.right_struct[i] = comb.width;
			}
			if(comb.right_struct[i] == comb.width) {
				comb.left_struct[i] = comb.width;
			}
		}

		for(int i = 0; i < 2; i++) {
			for(int j = 0; j < 2; j++) {
				if(left[i][j] == width) {
					comb.left[i][j] = width + n.left[i][j];
				}
				if(n.right[i][j] == n.width) {
					comb.right[i][j] = n.width + right[i][j];
				}
			}
		}

		int center[2];
		for(int i = 0; i < 2; i++) {
			center[i] = right[i][1] + n.left[i][0];
			comb.mid[i] = max({center[i], mid[i], n.mid[i]});
		}
		for(int i = 0; i < 2; i++) {
			for(int j = 0; j < 2; j++) {
				comb.mid[i] = max(comb.mid[i], comb.left[i][j]);
				comb.mid[i] = max(comb.mid[i], comb.right[i][j]);
			}
		}
		for(int i = 0; i < 2; i++) {
			comb.mid[i] = max(comb.mid[i], comb.left_struct[i]);
			comb.mid[i] = max(comb.mid[i], comb.right_struct[i]);
		}
		for(int i = 0; i < 2; i++) {
			comb.mid[i] = max(comb.mid[i], right_struct[i] + n.left[i][0]);
			comb.mid[i] = max(comb.mid[i], n.left_struct[i] + right[i][1]);
		}

		return comb;
	}
};

struct update {
	int val;
	node operator() (node n) {
		if(val) {
			swap(n.mid[0], n.mid[1]);
			for(int i = 0; i < 2; i++) {
				swap(n.left[0][i], n.left[1][i]);
				swap(n.right[0][i], n.right[1][i]);
			}
			swap(n.left_struct[0], n.left_struct[1]);
			swap(n.right_struct[0], n.right_struct[1]);
		}
		return n;
	}
	update operator+ (update u) {
		return {(val + u.val) & 1};
	}
};

int main(){
	fast_cin();
	// freopen("input.in","r",stdin);
	// freopen("output.out","w",stdout);
	int n, q; cin >> n >> q;
	string s; cin >> s;
	node empty;
	empty.width = 0;
	for(int i = 0; i < 2; i++) {
		empty.mid[i] = 0;
		empty.left_struct[i] = empty.right_struct[i] = 0;
		for(int j = 0; j < 2; j++) {
			empty.left[i][j] = 0;
			empty.right[i][j] = 0;
		}
	}
	seg_tree_lazy<node, update> st(n, empty, {0});
	vector<node> leaves;
	for(int t = 0; t < n; t++) {
		node now;
		now.width = 1;
		for(int i = 0; i < 2; i++) {
			now.mid[i] = 1;
			now.left_struct[i] = 1;
			now.right_struct[i] = 1;
			for(int j = 0; j < 2; j++) {
				now.left[i][j] = 0;
				now.right[i][j] = 0;
			}
		}
		if(s[t] == '<') {
			now.left[0][0] = now.right[0][0] = 1;
			now.left[1][1] = now.right[1][1] = 1;
		}
		else {
			now.left[0][1] = now.right[0][1] = 1;
			now.left[1][0] = now.right[1][0] = 1;
		}
		leaves.push_back(now);
	}
	st.set_leaves(leaves);
	while(q--) {
		int l, r; cin >> l >> r;
		l--; r--;
		st.upd(l, r, {1});
		cout << st.query(l, r).mid[0] << endl;
	}
	return 0;
}


/*input
5 6
><>><
2 4
3 5
1 5
1 3
2 4
1 5
*/

// Nihesh Anderson - knandy

#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;

typedef long long ll;
typedef long double ld;
typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> ordered_set; // find_by_order, order_of_key
ll MOD=1000000007;

#define endl '\n'
#define fast_cin() ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define pb push_back
ll INF = 2000000000000000001;
long double EPS = 1e-9;
ll power(ll a, ll n, ll md){if(n==0){return 1;}else{int res=power(a,n/2,md);res=(res*res)%md;if(n%2!=0){res=(res*a)%md;}return res;}}
random_device rndm;
mt19937 grndm(rndm());
void mix(int* a, int* b){shuffle(a,b,grndm);}

template<typename T, typename U> struct seg_tree_lazy {
    int S, H;

    T zero;
    vector<T> value;

    U noop;
    vector<bool> dirty;
    vector<U> prop;

    seg_tree_lazy<T, U>(int _S, T _zero = T(), U _noop = U()) {
        zero = _zero, noop = _noop;
        for (S = 1, H = 1; S < _S; ) S *= 2, H++;

        value.resize(2*S, zero);
        dirty.resize(2*S, false);
        prop.resize(2*S, noop);
    }

    void set_leaves(vector<T> &leaves) {
        copy(leaves.begin(), leaves.end(), value.begin() + S);

        for (int i = S - 1; i > 0; i--)
            value[i] = value[2 * i] + value[2 * i + 1];
    }

    void apply(int i, U &update) {
        value[i] = update(value[i]);
        if(i < S) {
            prop[i] = prop[i] + update;
            dirty[i] = true;
        }
    }

    void rebuild(int i) {
        for (int l = i/2; l; l /= 2) {
            T combined = value[2*l] + value[2*l+1];
            value[l] = prop[l](combined);
        }
    }

    void propagate(int i) {
        for (int h = H; h > 0; h--) {
            int l = i >> h;

            if (dirty[l]) {
                apply(2*l, prop[l]);
                apply(2*l+1, prop[l]);

                prop[l] = noop;
                dirty[l] = false;
            }
        }
    }

    void upd(int i, int j, U update) {
        i += S, j += S;
        propagate(i), propagate(j);

        for (int l = i, r = j; l <= r; l /= 2, r /= 2) {
            if((l&1) == 1) apply(l++, update);
            if((r&1) == 0) apply(r--, update);
        }

        rebuild(i), rebuild(j);
    }

    T query(int i, int j){
        i += S, j += S;
        propagate(i), propagate(j);

        T res_left = zero, res_right = zero;
        for(; i <= j; i /= 2, j /= 2){
            if((i&1) == 1) res_left = res_left + value[i++];
            if((j&1) == 0) res_right = value[j--] + res_right;
        }
        return res_left + res_right;
    }
};

struct node {
	int width, mid[2], left[2][2], right[2][2], left_struct[2], right_struct[2];
	node operator+ (node n) {
		node comb;
		comb.width = width + n.width;

		// fill left and right half of combined
		for(int i = 0; i < 2; i++) {
			for(int j = 0; j < 2; j++) {
				comb.left[i][j] = left[i][j];
				comb.right[i][j] = n.right[i][j];
			}
			comb.left_struct[i] = left_struct[i];
			comb.right_struct[i] = n.right_struct[i];
		}

		for(int i = 0; i < 2; i++) {
			if(left_struct[i] == width) {
				comb.left_struct[i] = width + n.left[i][0];
			}
			if(n.right_struct[i] == width) {
				comb.right_struct[i] = width + right[i][1];
			}
			if(comb.left_struct[i] == comb.width) {
				comb.right_struct[i] = comb.width;
			}
			if(comb.right_struct[i] == comb.width) {
				comb.left_struct[i] = comb.width;
			}
		}

		for(int i = 0; i < 2; i++) {
			for(int j = 0; j < 2; j++) {
				if(left[i][j] == width && n.left[i][j] == n.width) {
					comb.left[i][j] = width + n.width;
				}
				if(right[i][j] == width && n.right[i][j] == n.width) {
					comb.right[i][j] = width + n.width;
				}
			}
		}

		int center[2];
		for(int i = 0; i < 2; i++) {
			center[i] = right[i][1] + n.left[i][0];
			comb.mid[i] = max({center[i], mid[i], n.mid[i]});
		}
		for(int i = 0; i < 2; i++) {
			for(int j = 0; j < 2; j++) {
				comb.mid[i] = max(comb.mid[i], comb.left[i][j]);
				comb.mid[i] = max(comb.mid[i], comb.right[i][j]);
			}
		}
		for(int i = 0; i < 2; i++) {
			comb.mid[i] = max(comb.mid[i], comb.left_struct[i]);
			comb.mid[i] = max(comb.mid[i], comb.right_struct[i]);
		}

		return comb;
	}
};

struct update {
	int val;
	node operator() (node n) {
		if(val) {
			swap(n.mid[0], n.mid[1]);
			for(int i = 0; i < 2; i++) {
				swap(n.left[0][i], n.left[1][i]);
				swap(n.right[0][i], n.right[1][i]);
			}
			swap(n.left_struct[0], n.left_struct[1]);
			swap(n.right_struct[0], n.right_struct[1]);
		}
		return n;
	}
	update operator+ (update u) {
		return {(val + u.val) & 1};
	}
};

int main(){
	fast_cin();
	// freopen("input.in","r",stdin);
	// freopen("output.out","w",stdout);
	int n, q; cin >> n >> q;
	string s; cin >> s;
	node empty;
	empty.width = 0;
	for(int i = 0; i < 2; i++) {
		empty.mid[i] = 0;
		empty.left_struct[i] = empty.right_struct[i] = 0;
		for(int j = 0; j < 2; j++) {
			empty.left[i][j] = 0;
			empty.right[i][j] = 0;
		}
	}
	seg_tree_lazy<node, update> st(n, empty, {0});
	vector<node> leaves;
	for(int t = 0; t < n; t++) {
		node now;
		now.width = 1;
		for(int i = 0; i < 2; i++) {
			now.mid[i] = 1;
			now.left_struct[i] = 1;
			now.right_struct[i] = 1;
			for(int j = 0; j < 2; j++) {
				now.left[i][j] = 0;
				now.right[i][j] = 0;
			}
		}
		if(s[t] == '<') {
			now.left[0][0] = now.right[0][0] = 1;
			now.left[1][1] = now.right[1][1] = 1;
		}
		else {
			now.left[0][1] = now.right[0][1] = 1;
			now.left[1][0] = now.right[1][0] = 1;
		}
		leaves.push_back(now);
	}
	st.set_leaves(leaves);
	while(q--) {
		int l, r; cin >> l >> r;
		l--; r--;
		st.upd(l, r, {1});
		cout << st.query(l, r).mid[0] << endl;
	}
	return 0;
}


#include <stdio.h>
#include <algorithm>
#define MN 500000

const int INF = 0x3fffffff;

int n,q;
char str[MN+5];

struct Segment{
	bool ed;
	int len;
	Segment(){}
	Segment(bool arg1,int arg2){
		ed = arg1;
		len = arg2;
	}
};

struct Rnode{
	int ans;
	bool isComplete;
	Segment pre,suf;
};

struct Tnode{
	Rnode rnode[2];
	int flip,tag;
	Rnode& get(int x){
		return rnode[x^flip];
	}
}T[MN*4+5];

void construct(Rnode &node,int direction){
	node.ans = 1;
	node.isComplete = true;
	node.pre = Segment(direction,1);
	node.suf = Segment(direction,1);
}

void updateRnode(Rnode &node,const Rnode &ls,const Rnode &rs){
	if(ls.suf.ed == 0 && rs.pre.ed == 1){
		node.ans = std::max(ls.ans,rs.ans);
		node.isComplete = false;
		node.pre = ls.pre;
		node.suf = rs.suf;
	}else{
		node.ans = std::max({ls.ans,rs.ans,ls.suf.len+rs.pre.len});
		node.isComplete = (ls.isComplete && rs.isComplete);
		node.pre = ls.pre;
		if(ls.isComplete) node.pre.len += rs.pre.len;
		node.suf = rs.suf;
		if(rs.isComplete) node.suf.len += ls.suf.len;
	}
}

void updateTnode(int k){
	updateRnode(T[k].get(0),T[k<<1].get(0),T[k<<1|1].get(0));
	updateRnode(T[k].get(1),T[k<<1].get(1),T[k<<1|1].get(1));
}

void build(int k,int l,int r){
	if(l==r){
		construct(T[k].get(0),str[l]=='>');
		construct(T[k].get(1),str[l]=='<');
		return;
	}
	int mid=(l+r)>>1;
	build(k<<1,l,mid);
	build(k<<1|1,mid+1,r);
	updateTnode(k);
}

void flipTnode(int k){
	T[k].flip ^= 1;
	T[k].tag ^= 1;
}

void pushdown(int k){
	if(T[k].tag){
		flipTnode(k<<1);
		flipTnode(k<<1|1);
		T[k].tag = 0;
	}
}

void flip(int k,int l,int r,int L,int R){
	if(l==L&&r==R){
		flipTnode(k);
		return;
	}
	int mid = (l+r)>>1;
	pushdown(k);
	if(R<=mid) flip(k<<1,l,mid,L,R);
	else if(L>mid) flip(k<<1|1,mid+1,r,L,R);
	else{
		flip(k<<1,l,mid,L,mid);
		flip(k<<1|1,mid+1,r,mid+1,R);
	}
	updateTnode(k);
}

Rnode query(int k,int l,int r,int L,int R){
	if(l==L&&r==R){
		return T[k].get(0);
	}
	int mid = (l+r)>>1;
	pushdown(k);
	if(R<=mid) return query(k<<1,l,mid,L,R);
	else if(L>mid) return query(k<<1|1,mid+1,r,L,R);
	else{
		Rnode node;
		updateRnode(node,query(k<<1,l,mid,L,mid),query(k<<1|1,mid+1,r,mid+1,R));
		return node;
	}
}

int main(){
	#ifdef LOCAL
		freopen("sample.in","r",stdin);
	#endif
	scanf("%d%d",&n,&q);
	scanf("%s",&str[1]);
	build(1,1,n);
	for(int l,r;q--;){
		scanf("%d%d",&l,&r);
		flip(1,1,n,l,r);
		printf("%d\n",query(1,1,n,l,r).ans);
	}
}


#pragma GCC optimize("Ofast","unroll-loops","omit-frame-pointer","inline")
#pragma GCC option("arch=native","tune=native","no-zero-upper")
#pragma GCC target("avx2")
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<ctime>
#include<cmath>
#define ll long long
#define gc getchar()
#define I inline
using namespace std;
const int N=5e5+5;
template<class o>void qr(o &x)
{
	x=0;char c=gc;int f=1;while(c<'0'||c>'9'){if(c=='-')f=-1;c=gc;}
	while(c>='0'&&c<='9'){x=x*10+(c^48);c=gc;}x*=f;
}
template<class o>void qw(o x){if(x<0)putchar('-'),x=-x;if(x/10)qw(x/10);putchar(x%10+48);}
struct SGT
{
	int l[2],m[2],r[2],S;bool rv;
	/*
	l[0]>0 means sufix <<<<<<<....< l[0]<0 means >><<<...<  or >>>>>...>>(this state means l[0]=r[0]=S or other ....)
	r[0]>0 means the same as l[0]>0,r[0]<0 means the same as l[0]<0
	the others are the same.
	*/
	I void set(bool v)
	{
		m[0]=m[1]=1;S=1;rv=0;
		if(v)r[0]=1,l[0]=-1,r[1]=-1,l[1]=1;
		else r[1]=1,l[1]=-1,r[0]=-1,l[0]=1;
	}
	I void rev(){swap(l[0],l[1]);swap(m[0],m[1]);swap(r[0],r[1]);rv^=1;}
	friend SGT operator +(const SGT &l,const SGT &r)
	{
		SGT n;n.S=l.S+r.S;int L=l.S,R=r.S;n.rv=0;
		for(int i=0;i<2;i++)
		{
			n.l[i]=l.l[i];n.r[i]=r.r[i];
			if(l.l[i]>0)n.l[i]+=(l.l[i]==L&&r.l[i]>0?r.l[i]:0);
			else if(l.l[i]==-L)if(l.r[i]==L||r.l[i]>0)n.l[i]-=abs(r.l[i]);
			if(r.r[i]>0)n.r[i]+=(r.r[i]==R&&l.r[i]>0?l.r[i]:0);
			else if(r.r[i]==-R)if(r.l[i]==R||l.r[i]>0)n.r[i]-=abs(l.r[i]);
			n.m[i]=max(l.m[i],r.m[i]);
			if(l.r[i]>0||r.l[i]>0)n.m[i]=max(n.m[i],abs(l.r[i])+abs(r.l[i]));
		}
		return n;
	}
}t[N<<2],cur;char s[N];int cl=0;
void pushdown(int p){if(t[p].rv){t[p<<1].rev();t[p<<1|1].rev();t[p].rv=0;}}
void build(int p,int l,int r)
{
	t[p].S=r-l+1;if(l==r){t[p].set(s[l]=='>');return ;}
	int mid=l+r>>1;build(p<<1,l,mid);build(p<<1|1,mid+1,r);
	t[p]=t[p<<1]+t[p<<1|1];
}
void upd(int p,int l,int r,int ql,int qr)
{
	if(ql<=l&&qr>=r){t[p].rev();if(cl)cur=cur+t[p];else cur=t[p];++cl;return ;}
	int mid=l+r>>1;pushdown(p);if(ql<=mid)upd(p<<1,l,mid,ql,qr);if(qr>mid)upd(p<<1|1,mid+1,r,ql,qr);
	t[p]=t[p<<1]+t[p<<1|1];
}
int main()
{
	int n,m;qr(n),qr(m);
	scanf("%s",s+1);
	build(1,1,n);
	for(int i=1;i<=m;i++)
	{
		int l,r;qr(l),qr(r);
		upd(1,1,n,l,r);cl=0;
		qw(cur.m[0]);puts("");
	}
	return 0;
}


#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<ctime>
#include<cmath>
#define ll long long
#define gc getchar()
#define I inline
using namespace std;
const int N=5e5+5;
template<class o>void qr(o &x)
{
	x=0;char c=gc;int f=1;while(c<'0'||c>'9'){if(c=='-')f=-1;c=gc;}
	while(c>='0'&&c<='9'){x=x*10+(c^48);c=gc;}x*=f;
}
template<class o>void qw(o x){if(x<0)putchar('-'),x=-x;if(x/10)qw(x/10);putchar(x%10+48);}
struct SGT
{
	int l[2],m[2],r[2],S;bool rv;
	/*
	l[0]>0 means sufix <<<<<<<....< l[0]<0 means >><<<...<  or >>>>>...>>(this state means l[0]=r[0]=S or other ....)
	r[0]>0 means the same as l[0]>0,r[0]<0 means the same as l[0]<0
	the others are the same.
	*/
	I void set(bool v)
	{
		m[0]=m[1]=1;S=1;rv=0;
		if(v)r[0]=1,l[0]=-1,r[1]=-1,l[1]=1;
		else r[1]=1,l[1]=-1,r[0]=-1,l[0]=1;
	}
	I void rev(){swap(l[0],l[1]);swap(m[0],m[1]);swap(r[0],r[1]);rv^=1;}
	friend SGT operator +(const SGT &l,const SGT &r)
	{
		SGT n;n.S=l.S+r.S;int L=l.S,R=r.S;n.rv=0;
		for(int i=0;i<2;i++)
		{
			n.l[i]=l.l[i];n.r[i]=r.r[i];
			if(l.l[i]>0)n.l[i]+=(l.l[i]==L&&r.l[i]>0?r.l[i]:0);
			else if(l.l[i]==-L)if(l.r[i]==L||r.l[i]>0)n.l[i]-=abs(r.l[i]);
			if(r.r[i]>0)n.r[i]+=(r.r[i]==R&&l.r[i]>0?l.r[i]:0);
			else if(r.r[i]==-R)if(r.l[i]==R||l.r[i]>0)n.r[i]-=abs(l.r[i]);
			n.m[i]=max(l.m[i],r.m[i]);
			if(l.r[i]>0||r.l[i]>0)n.m[i]=max(n.m[i],abs(l.r[i])+abs(r.l[i]));
		}
		return n;
	}
}t[N<<2],cur;char s[N];int cl=0;
void pushdown(int p){if(t[p].rv){t[p<<1].rev();t[p<<1|1].rev();t[p].rv=0;}}
void build(int p,int l,int r)
{
	t[p].S=r-l+1;if(l==r){t[p].set(s[l]=='>');return ;}
	int mid=l+r>>1;build(p<<1,l,mid);build(p<<1|1,mid+1,r);
	t[p]=t[p<<1]+t[p<<1|1];
}
void upd(int p,int l,int r,int ql,int qr)
{
	if(ql<=l&&qr>=r){t[p].rev();if(cl)cur=cur+t[p];else cur=t[p];++cl;return ;}
	int mid=l+r>>1;pushdown(p);if(ql<=mid)upd(p<<1,l,mid,ql,qr);if(qr>mid)upd(p<<1|1,mid+1,r,ql,qr);
	t[p]=t[p<<1]+t[p<<1|1];
}
int main()
{
	int n,m;qr(n),qr(m);
	scanf("%s",s+1);
	build(1,1,n);
	for(int i=1;i<=m;i++)
	{
		int l,r;qr(l),qr(r);
		upd(1,1,n,l,r);cl=0;
		qw(cur.m[0]);puts("");
	}
	return 0;
}


#pragma GCC optimize(2)
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<ctime>
#include<cmath>
#define ll long long
#define gc getchar()
#define I inline
using namespace std;
const int N=5e5+5;
template<class o>void qr(o &x)
{
	x=0;char c=gc;int f=1;while(c<'0'||c>'9'){if(c=='-')f=-1;c=gc;}
	while(c>='0'&&c<='9'){x=x*10+(c^48);c=gc;}x*=f;
}
template<class o>void qw(o x){if(x<0)putchar('-'),x=-x;if(x/10)qw(x/10);putchar(x%10+48);}
struct SGT
{
	int l[2],m[2],r[2],S;bool rv;
	/*
	l[0]>0 means sufix <<<<<<<....< l[0]<0 means >><<<...<  or >>>>>...>>(this state means l[0]=r[0]=S or other ....)
	r[0]>0 means the same as l[0]>0,r[0]<0 means the same as l[0]<0
	the others are the same.
	*/
	I void set(bool v)
	{
		m[0]=m[1]=1;S=1;rv=0;
		if(v)r[0]=1,l[0]=-1,r[1]=-1,l[1]=1;
		else r[1]=1,l[1]=-1,r[0]=-1,l[0]=1;
	}
	I void rev(){swap(l[0],l[1]);swap(m[0],m[1]);swap(r[0],r[1]);rv^=1;}
	friend SGT operator +(const SGT &l,const SGT &r)
	{
		SGT n;n.S=l.S+r.S;int L=l.S,R=r.S;n.rv=0;
		for(int i=0;i<2;i++)
		{
			n.l[i]=l.l[i];n.r[i]=r.r[i];
			if(l.l[i]>0)n.l[i]+=(l.l[i]==L&&r.l[i]>0?r.l[i]:0);
			else if(l.l[i]==-L)if(l.r[i]==L||r.l[i]>0)n.l[i]-=abs(r.l[i]);
			if(r.r[i]>0)n.r[i]+=(r.r[i]==R&&l.r[i]>0?l.r[i]:0);
			else if(r.r[i]==-R)if(r.l[i]==R||l.r[i]>0)n.r[i]-=abs(l.r[i]);
			n.m[i]=max(l.m[i],r.m[i]);
			if(l.r[i]>0||r.l[i]>0)n.m[i]=max(n.m[i],abs(l.r[i])+abs(r.l[i]));
		}
		return n;
	}
}t[N<<2],cur;char s[N];int cl=0;
void pushdown(int p){if(t[p].rv){t[p<<1].rev();t[p<<1|1].rev();t[p].rv=0;}}
void build(int p,int l,int r)
{
	t[p].S=r-l+1;if(l==r){t[p].set(s[l]=='>');return ;}
	int mid=l+r>>1;build(p<<1,l,mid);build(p<<1|1,mid+1,r);
	t[p]=t[p<<1]+t[p<<1|1];
}
void upd(int p,int l,int r,int ql,int qr)
{
	if(ql<=l&&qr>=r){t[p].rev();if(cl)cur=cur+t[p];else cur=t[p];++cl;return ;}
	int mid=l+r>>1;pushdown(p);if(ql<=mid)upd(p<<1,l,mid,ql,qr);if(qr>mid)upd(p<<1|1,mid+1,r,ql,qr);
	t[p]=t[p<<1]+t[p<<1|1];
}
int main()
{
	int n,m;qr(n),qr(m);
	scanf("%s",s+1);
	build(1,1,n);
	for(int i=1;i<=m;i++)
	{
		int l,r;qr(l),qr(r);
		upd(1,1,n,l,r);cl=0;
		qw(cur.m[0]);puts("");
	}
	return 0;
}


// CF 1371 F
#include<bits/stdc++.h>
using namespace std;
const int N = 5e5 + 7;
int n,q;
char s[N];
int a[N] = {0};
struct Node{
    int l,r;
    int lmx[2],rmx[2],mx[2];
    int slmx[2],srmx[2],smx[2];
    bool rev;
}tr[N*4];
void pushup(int u,int tp){
    tr[u].lmx[tp] = tr[u*2].lmx[tp];
    if(tr[u*2].lmx[tp] == tr[u*2].r-tr[u*2].l+1)
        tr[u].lmx[tp] = tr[u*2].lmx[tp] + tr[u*2+1].lmx[tp];
    tr[u].rmx[tp] = tr[u*2+1].rmx[tp];
    if(tr[u*2+1].rmx[tp] == tr[u*2+1].r-tr[u*2+1].l+1)
        tr[u].rmx[tp] = tr[u*2+1].rmx[tp] + tr[u*2].rmx[tp];
    tr[u].mx[tp] = max(tr[u*2].mx[tp],tr[u*2+1].mx[tp]);
    tr[u].mx[tp] = max(tr[u].mx[tp],tr[u*2].rmx[tp]+tr[u*2+1].lmx[tp]);
}
void pushup2(int u,int tp){
	tr[u].slmx[tp] = tr[u].lmx[tp],tr[u].srmx[tp] = tr[u].rmx[tp],tr[u].smx[tp] = tr[u].mx[tp];
	tr[u].slmx[tp] = max(tr[u].slmx[tp],tr[u*2].slmx[tp]);
    if(tr[u*2].slmx[tp] == tr[u*2].r-tr[u*2].l+1)
        tr[u].slmx[tp] = max(tr[u].slmx[tp],tr[u*2].slmx[tp] + tr[u*2+1].lmx[tp]);
    if(tr[u*2].lmx[tp^1] == tr[u*2].r-tr[u*2].l+1)
        tr[u].slmx[tp] = max(tr[u].slmx[tp],tr[u*2].lmx[tp^1] + tr[u*2+1].slmx[tp]);
    tr[u].srmx[tp] = max(tr[u].srmx[tp],tr[u*2+1].srmx[tp]);
    if(tr[u*2+1].rmx[tp] == tr[u*2+1].r-tr[u*2+1].l+1)
        tr[u].srmx[tp] = max(tr[u].srmx[tp],tr[u*2].srmx[tp] + tr[u*2+1].rmx[tp]);
    if(tr[u*2+1].srmx[tp] == tr[u*2+1].r-tr[u*2+1].l+1)
        tr[u].srmx[tp] = max(tr[u].srmx[tp],tr[u*2].rmx[tp^1] + tr[u*2+1].srmx[tp]);
    tr[u].smx[tp] = max(tr[u].smx[tp],max(tr[u*2].smx[tp],tr[u*2+1].smx[tp]));
    tr[u].smx[tp] = max(tr[u].smx[tp],tr[u*2].rmx[tp^1]+tr[u*2+1].slmx[tp]);
    tr[u].smx[tp] = max(tr[u].smx[tp],tr[u*2].srmx[tp]+tr[u*2+1].lmx[tp]);
}
void pushdown(int u){
    if(tr[u].rev){
        tr[u*2].rev ^= 1;
        swap(tr[u*2].mx[0],tr[u*2].mx[1]);
        swap(tr[u*2].smx[0],tr[u*2].smx[1]);
        swap(tr[u*2].lmx[0],tr[u*2].lmx[1]);
        swap(tr[u*2].rmx[0],tr[u*2].rmx[1]);
        swap(tr[u*2].slmx[0],tr[u*2].slmx[1]);
        swap(tr[u*2].srmx[0],tr[u*2].srmx[1]);
        tr[u*2+1].rev ^= 1;
        swap(tr[u*2+1].mx[0],tr[u*2+1].mx[1]);
        swap(tr[u*2+1].smx[0],tr[u*2+1].smx[1]);
        swap(tr[u*2+1].lmx[0],tr[u*2+1].lmx[1]);
        swap(tr[u*2+1].rmx[0],tr[u*2+1].rmx[1]);
        swap(tr[u*2+1].slmx[0],tr[u*2+1].slmx[1]);
        swap(tr[u*2+1].srmx[0],tr[u*2+1].srmx[1]);
        tr[u].rev = 0;
    }
}
void bt(int u,int l,int r){
    tr[u].l = l,tr[u].r = r;
    tr[u].rev = 0;
    if(l==r){
        tr[u].slmx[a[l]] = tr[u].srmx[a[l]] = tr[u].smx[a[l]] = tr[u].lmx[a[l]] = tr[u].rmx[a[l]] = tr[u].mx[a[l]] = 1;
        return;
    }
    int mid = (l+r)/2;
    bt(u*2,l,mid);
    bt(u*2+1,mid+1,r);
    pushup(u,0),pushup(u,1);
    pushup2(u,0),pushup2(u,1);;
}
void chg(int u,int l,int r){
    if(l<=tr[u].l&&r>=tr[u].r){
        swap(tr[u].mx[0],tr[u].mx[1]);
        swap(tr[u].smx[0],tr[u].smx[1]);
        swap(tr[u].lmx[0],tr[u].lmx[1]);
        swap(tr[u].rmx[0],tr[u].rmx[1]);
        swap(tr[u].slmx[0],tr[u].slmx[1]);
        swap(tr[u].srmx[0],tr[u].srmx[1]);
        tr[u].rev ^= 1;
        return;
    }
    pushdown(u);
    int mid = (tr[u].l+tr[u].r)/2;
    if(l<=mid) chg(u*2,l,r);
    if(r>mid) chg(u*2+1,l,r);
    pushup(u,0),pushup(u,1);
    pushup2(u,0),pushup2(u,1);
}
Node pushupn(Node x,Node y){
    Node res;
    res.l = x.l,res.r = y.r;
    res.rev = 0;
    for(int tp = 0;tp<2;tp++){
    res.lmx[tp] = x.lmx[tp];
    if(x.lmx[tp] == x.r-x.l+1)
        res.lmx[tp] = x.lmx[tp] + y.lmx[tp];
    res.rmx[tp] = y.rmx[tp];
    if(y.rmx[tp] == y.r-y.l+1)
        res.rmx[tp] = y.rmx[tp] + x.rmx[tp];
    res.mx[tp] = max(x.mx[tp],y.mx[tp]);
    res.mx[tp] = max(res.mx[tp],x.rmx[tp]+y.lmx[tp]);
    }
    for(int tp = 0;tp<2;tp++){
        res.slmx[tp] = res.lmx[tp],res.srmx[tp] = res.rmx[tp],res.smx[tp] = res.mx[tp];
	res.slmx[tp] = max(res.slmx[tp],x.slmx[tp]);
    if(x.slmx[tp] == x.r-x.l+1)
        res.slmx[tp] = max(res.slmx[tp],x.slmx[tp] + y.lmx[tp]);
    if(x.lmx[tp^1] == x.r-x.l+1)
        res.slmx[tp] = max(res.slmx[tp],x.lmx[tp^1] + y.slmx[tp]);
    res.srmx[tp] = max(res.srmx[tp],y.srmx[tp]);
    if(y.srmx[tp] == y.r-y.l+1)
        res.srmx[tp] = max(res.srmx[tp],x.rmx[tp^1] + y.srmx[tp]);
    if(y.rmx[tp] == y.r-y.l+1)
        res.srmx[tp] = max(res.srmx[tp],x.srmx[tp] + y.rmx[tp]);
    res.smx[tp] = max(res.smx[tp],max(x.smx[tp],y.smx[tp]));
    res.smx[tp] = max(res.smx[tp],x.rmx[tp^1]+y.slmx[tp]);
    res.smx[tp] = max(res.smx[tp],x.srmx[tp]+y.lmx[tp]);
    }
    return res;
}
Node qry(int u,int l,int r){
    if(l==tr[u].l&&r==tr[u].r)
        return tr[u];
    pushdown(u);
    int mid = (tr[u].l+tr[u].r)/2;
    if(r<=mid) return qry(u*2,l,r);
    else if(l>mid) return qry(u*2+1,l,r);
    else return pushupn(qry(u*2,l,mid),qry(u*2+1,mid+1,r));
}
int main(){
    scanf("%d%d",&n,&q);
    cin >> (s+1);
    for(int i = 1;i<=n;i++){
        if(s[i]=='<') a[i] = 1;
        else a[i] = 0;
    }
    bt(1,1,n);
    for(int i = 1;i<=q;i++){
        int l,r;
        scanf("%d%d",&l,&r);
        chg(1,l,r);
        Node res = qry(1,l,r);
        printf("%d\n",max(res.mx[1],max(res.smx[1],res.mx[0])));
    }
    return 0;
}


// CF 1371 F
#include<bits/stdc++.h>
using namespace std;
const int N = 5e5 + 7;
int n,q;
char s[N];
int a[N] = {0};
struct Node{
    int l,r;
    int lmx[2],rmx[2],mx[2];
    int slmx[2],srmx[2],smx[2];
    bool rev;
}tr[N*4];
void pushup(int u,int tp){
    tr[u].lmx[tp] = tr[u*2].lmx[tp];
    if(tr[u*2].lmx[tp] == tr[u*2].r-tr[u*2].l+1)
        tr[u].lmx[tp] = tr[u*2].lmx[tp] + tr[u*2+1].lmx[tp];
    tr[u].rmx[tp] = tr[u*2+1].rmx[tp];
    if(tr[u*2+1].rmx[tp] == tr[u*2+1].r-tr[u*2+1].l+1)
        tr[u].rmx[tp] = tr[u*2+1].rmx[tp] + tr[u*2].rmx[tp];
    tr[u].mx[tp] = max(tr[u*2].mx[tp],tr[u*2+1].mx[tp]);
    tr[u].mx[tp] = max(tr[u].mx[tp],tr[u*2].rmx[tp]+tr[u*2+1].lmx[tp]);
}
void pushup2(int u,int tp){
	tr[u].slmx[tp] = tr[u].lmx[tp],tr[u].srmx[tp] = tr[u].rmx[tp],tr[u].smx[tp] = tr[u].mx[tp];
	tr[u].slmx[tp] = max(tr[u].slmx[tp],tr[u*2].slmx[tp]);
    if(tr[u*2].slmx[tp] == tr[u*2].r-tr[u*2].l+1)
        tr[u].slmx[tp] = max(tr[u].slmx[tp],tr[u*2].slmx[tp] + tr[u*2+1].lmx[tp]);
    if(tr[u*2].lmx[tp^1] == tr[u*2].r-tr[u*2].l+1)
        tr[u].slmx[tp] = max(tr[u].slmx[tp],tr[u*2].lmx[tp^1] + tr[u*2+1].slmx[tp]);
    tr[u].srmx[tp] = max(tr[u].srmx[tp],tr[u*2+1].srmx[tp]);
    if(tr[u*2+1].rmx[tp] == tr[u*2+1].r-tr[u*2+1].l+1)
        tr[u].srmx[tp] = max(tr[u].srmx[tp],tr[u*2].srmx[tp] + tr[u*2+1].rmx[tp]);
    if(tr[u*2+1].srmx[tp] == tr[u*2+1].r-tr[u*2+1].l+1)
        tr[u].srmx[tp] = max(tr[u].srmx[tp],tr[u*2].rmx[tp^1] + tr[u*2+1].srmx[tp]);
    tr[u].smx[tp] = max(tr[u].smx[tp],max(tr[u*2].smx[tp],tr[u*2+1].smx[tp]));
    tr[u].smx[tp] = max(tr[u].smx[tp],tr[u*2].rmx[tp^1]+tr[u*2+1].slmx[tp]);
    tr[u].smx[tp] = max(tr[u].smx[tp],tr[u*2].srmx[tp]+tr[u*2+1].lmx[tp]);
}
void pushdown(int u){
    if(tr[u].rev){
        tr[u*2].rev ^= 1;
        swap(tr[u*2].mx[0],tr[u*2].mx[1]);
        swap(tr[u*2].smx[0],tr[u*2].smx[1]);
        swap(tr[u*2].lmx[0],tr[u*2].lmx[1]);
        swap(tr[u*2].rmx[0],tr[u*2].rmx[1]);
        swap(tr[u*2].slmx[0],tr[u*2].slmx[1]);
        swap(tr[u*2].srmx[0],tr[u*2].srmx[1]);
        tr[u*2+1].rev ^= 1;
        swap(tr[u*2+1].mx[0],tr[u*2+1].mx[1]);
        swap(tr[u*2+1].smx[0],tr[u*2+1].smx[1]);
        swap(tr[u*2+1].lmx[0],tr[u*2+1].lmx[1]);
        swap(tr[u*2+1].rmx[0],tr[u*2+1].rmx[1]);
        swap(tr[u*2+1].slmx[0],tr[u*2+1].slmx[1]);
        swap(tr[u*2+1].srmx[0],tr[u*2+1].srmx[1]);
        tr[u].rev = 0;
    }
}
void bt(int u,int l,int r,int tp){
    tr[u].l = l,tr[u].r = r;
    tr[u].rev = 0;
    if(l==r){
        if(!(a[l]^tp))tr[u].slmx[tp] = tr[u].srmx[tp] = tr[u].smx[tp] = tr[u].lmx[tp] = tr[u].rmx[tp] = tr[u].mx[tp] = 1;
        return;
    }
    int mid = (l+r)/2;
    bt(u*2,l,mid,tp);
    bt(u*2+1,mid+1,r,tp);
    pushup(u,tp);
    pushup2(u,tp);
}
void chg(int u,int l,int r){
    if(l<=tr[u].l&&r>=tr[u].r){
        swap(tr[u].mx[0],tr[u].mx[1]);
        swap(tr[u].smx[0],tr[u].smx[1]);
        swap(tr[u].lmx[0],tr[u].lmx[1]);
        swap(tr[u].rmx[0],tr[u].rmx[1]);
        swap(tr[u].slmx[0],tr[u].slmx[1]);
        swap(tr[u].srmx[0],tr[u].srmx[1]);
        tr[u].rev ^= 1;
        return;
    }
    pushdown(u);
    int mid = (tr[u].l+tr[u].r)/2;
    if(l<=mid) chg(u*2,l,r);
    if(r>mid) chg(u*2+1,l,r);
    pushup(u,0),pushup(u,1);
    pushup2(u,0),pushup2(u,1);
}
Node pushupn(Node x,Node y){
    Node res;
    res.l = x.l,res.r = y.r;
    res.rev = 0;
    for(int tp = 0;tp<2;tp++){
    res.lmx[tp] = x.lmx[tp];
    if(x.lmx[tp] == x.r-x.l+1)
        res.lmx[tp] = x.lmx[tp] + y.lmx[tp];
    res.rmx[tp] = y.rmx[tp];
    if(y.rmx[tp] == y.r-y.l+1)
        res.rmx[tp] = y.rmx[tp] + x.rmx[tp];
    res.mx[tp] = max(x.mx[tp],y.mx[tp]);
    res.mx[tp] = max(res.mx[tp],x.rmx[tp]+y.lmx[tp]);
    }
    for(int tp = 0;tp<2;tp++){
        res.slmx[tp] = res.lmx[tp],res.srmx[tp] = res.rmx[tp],res.smx[tp] = res.mx[tp];
	res.slmx[tp] = max(res.slmx[tp],x.slmx[tp]);
    if(x.slmx[tp] == x.r-x.l+1)
        res.slmx[tp] = max(res.slmx[tp],x.slmx[tp] + y.lmx[tp]);
    if(x.lmx[tp^1] == x.r-x.l+1)
        res.slmx[tp] = max(res.slmx[tp],x.lmx[tp^1] + y.slmx[tp]);
    res.srmx[tp] = max(res.srmx[tp],y.srmx[tp]);
    if(y.srmx[tp] == y.r-y.l+1)
        res.srmx[tp] = max(res.srmx[tp],x.rmx[tp^1] + y.srmx[tp]);
    if(y.rmx[tp] == y.r-y.l+1)
        res.srmx[tp] = max(res.srmx[tp],x.srmx[tp] + y.rmx[tp]);
    res.smx[tp] = max(res.smx[tp],max(x.smx[tp],y.smx[tp]));
    res.smx[tp] = max(res.smx[tp],x.rmx[tp^1]+y.slmx[tp]);
    res.smx[tp] = max(res.smx[tp],x.srmx[tp]+y.lmx[tp]);
    }
    return res;
}
Node qry(int u,int l,int r){
    if(l==tr[u].l&&r==tr[u].r)
        return tr[u];
    pushdown(u);
    int mid = (tr[u].l+tr[u].r)/2;
    if(r<=mid) return qry(u*2,l,r);
    else if(l>mid) return qry(u*2+1,l,r);
    else return pushupn(qry(u*2,l,mid),qry(u*2+1,mid+1,r));
}
int main(){
    scanf("%d%d",&n,&q);
    cin >> (s+1);
    for(int i = 1;i<=n;i++){
        if(s[i]=='<') a[i] = 1;
        else a[i] = 0;
    }
    bt(1,1,n,0);
    bt(1,1,n,1);
    for(int i = 1;i<=q;i++){
        int l,r;
        scanf("%d%d",&l,&r);
        chg(1,l,r);
        Node res = qry(1,l,r);
        printf("%d\n",max(res.mx[1],max(res.smx[1],res.mx[0])));
    }
    return 0;
}


// CF 1371 F
#include<bits/stdc++.h>
using namespace std;
const int N = 5e5 + 7;
int n,q;
char s[N];
int a[N] = {0};
struct Node{
    int l,r;
    int lmx[2],rmx[2],mx[2];
    int slmx[2],srmx[2],smx[2];
    bool rev;
}tr[N*4];
void pushup(int u,int tp){
    tr[u].lmx[tp] = tr[u*2].lmx[tp];
    if(tr[u*2].lmx[tp] == tr[u*2].r-tr[u*2].l+1)
        tr[u].lmx[tp] = tr[u*2].lmx[tp] + tr[u*2+1].lmx[tp];
    tr[u].rmx[tp] = tr[u*2+1].rmx[tp];
    if(tr[u*2+1].rmx[tp] == tr[u*2+1].r-tr[u*2+1].l+1)
        tr[u].rmx[tp] = tr[u*2+1].rmx[tp] + tr[u*2].rmx[tp];
    tr[u].mx[tp] = max(tr[u*2].mx[tp],tr[u*2+1].mx[tp]);
    tr[u].mx[tp] = max(tr[u].mx[tp],tr[u*2].rmx[tp]+tr[u*2+1].lmx[tp]);
}
void pushup2(int u,int tp){
	tr[u].slmx[tp] = tr[u].lmx[tp],tr[u].srmx[tp] = tr[u].rmx[tp],tr[u].smx[tp] = tr[u].mx[tp];
	tr[u].slmx[tp] = max(tr[u].slmx[tp],tr[u*2].slmx[tp]);
    if(tr[u*2].slmx[tp] == tr[u*2].r-tr[u*2].l+1)
        tr[u].slmx[tp] = max(tr[u].slmx[tp],tr[u*2].slmx[tp] + tr[u*2+1].lmx[tp]);
    if(tr[u*2].lmx[tp^1] == tr[u*2].r-tr[u*2].l+1)
        tr[u].slmx[tp] = max(tr[u].slmx[tp],tr[u*2].lmx[tp^1] + tr[u*2+1].slmx[tp]);
    tr[u].srmx[tp] = max(tr[u].srmx[tp],tr[u*2+1].srmx[tp]);
    if(tr[u*2+1].srmx[tp] == tr[u*2+1].r-tr[u*2+1].l+1)
        tr[u].srmx[tp] = max(tr[u].srmx[tp],tr[u*2].rmx[tp^1] + tr[u*2+1].srmx[tp]);
    if(tr[u*2+1].rmx[tp] == tr[u*2+1].r-tr[u*2+1].l+1)
        tr[u].srmx[tp] = max(tr[u].srmx[tp],tr[u*2].srmx[tp] + tr[u*2+1].rmx[tp]);
    tr[u].smx[tp] = max(tr[u].smx[tp],max(tr[u*2].smx[tp],tr[u*2+1].smx[tp]));
    tr[u].smx[tp] = max(tr[u].smx[tp],tr[u*2].rmx[tp^1]+tr[u*2+1].slmx[tp]);
    tr[u].smx[tp] = max(tr[u].smx[tp],tr[u*2].srmx[tp]+tr[u*2+1].lmx[tp]);
}
void pushdown(int u){
    if(tr[u].rev){
        tr[u*2].rev ^= 1;
        swap(tr[u*2].mx[0],tr[u*2].mx[1]);
        swap(tr[u*2].smx[0],tr[u*2].smx[1]);
        swap(tr[u*2].lmx[0],tr[u*2].lmx[1]);
        swap(tr[u*2].rmx[0],tr[u*2].rmx[1]);
        swap(tr[u*2].slmx[0],tr[u*2].slmx[1]);
        swap(tr[u*2].srmx[0],tr[u*2].srmx[1]);
        tr[u*2+1].rev ^= 1;
        swap(tr[u*2+1].mx[0],tr[u*2+1].mx[1]);
        swap(tr[u*2+1].smx[0],tr[u*2+1].smx[1]);
        swap(tr[u*2+1].lmx[0],tr[u*2+1].lmx[1]);
        swap(tr[u*2+1].rmx[0],tr[u*2+1].rmx[1]);
        swap(tr[u*2+1].slmx[0],tr[u*2+1].slmx[1]);
        swap(tr[u*2+1].srmx[0],tr[u*2+1].srmx[1]);
        tr[u].rev = 0;
    }
}
void bt(int u,int l,int r,int tp){
    tr[u].l = l,tr[u].r = r;
    tr[u].rev = 0;
    if(l==r){
        if(!(a[l]^tp))tr[u].slmx[tp] = tr[u].srmx[tp] = tr[u].smx[tp] = tr[u].lmx[tp] = tr[u].rmx[tp] = tr[u].mx[tp] = 1;
        return;
    }
    int mid = (l+r)/2;
    bt(u*2,l,mid,tp);
    bt(u*2+1,mid+1,r,tp);
    pushup(u,tp);
    pushup2(u,tp);
}
void chg(int u,int l,int r){
    if(l<=tr[u].l&&r>=tr[u].r){
        swap(tr[u].mx[0],tr[u].mx[1]);
        swap(tr[u].smx[0],tr[u].smx[1]);
        swap(tr[u].lmx[0],tr[u].lmx[1]);
        swap(tr[u].rmx[0],tr[u].rmx[1]);
        swap(tr[u].slmx[0],tr[u].slmx[1]);
        swap(tr[u].srmx[0],tr[u].srmx[1]);
        tr[u].rev ^= 1;
        return;
    }
    pushdown(u);
    int mid = (tr[u].l+tr[u].r)/2;
    if(l<=mid) chg(u*2,l,r);
    if(r>mid) chg(u*2+1,l,r);
    pushup(u,0),pushup(u,1);
    pushup2(u,0),pushup2(u,1);
}
Node pushupn(Node x,Node y){
    Node res;
    res.l = x.l,res.r = y.r;
    res.rev = 0;
    for(int tp = 0;tp<2;tp++){
    res.lmx[tp] = x.lmx[tp];
    if(x.lmx[tp] == x.r-x.l+1)
        res.lmx[tp] = x.lmx[tp] + y.lmx[tp];
    res.rmx[tp] = y.rmx[tp];
    if(y.rmx[tp] == y.r-y.l+1)
        res.rmx[tp] = y.rmx[tp] + x.rmx[tp];
    res.mx[tp] = max(x.mx[tp],y.mx[tp]);
    res.mx[tp] = max(res.mx[tp],x.rmx[tp]+y.lmx[tp]);
    }
    for(int tp = 0;tp<2;tp++){
        res.slmx[tp] = res.lmx[tp],res.srmx[tp] = res.rmx[tp],res.smx[tp] = res.mx[tp];
	res.slmx[tp] = max(res.slmx[tp],x.slmx[tp]);
    if(x.slmx[tp] == x.r-x.l+1)
        res.slmx[tp] = max(res.slmx[tp],x.slmx[tp] + y.lmx[tp]);
    if(x.lmx[tp^1] == x.r-x.l+1)
        res.slmx[tp] = max(res.slmx[tp],x.lmx[tp^1] + y.slmx[tp]);
    res.srmx[tp] = max(res.srmx[tp],y.srmx[tp]);
    if(y.srmx[tp] == y.r-y.l+1)
        res.srmx[tp] = max(res.srmx[tp],x.rmx[tp^1] + y.srmx[tp]);
    if(y.rmx[tp] == y.r-y.l+1)
        res.srmx[tp] = max(res.srmx[tp],x.srmx[tp] + y.rmx[tp]);
    res.smx[tp] = max(res.smx[tp],max(x.smx[tp],y.smx[tp]));
    res.smx[tp] = max(res.smx[tp],x.rmx[tp^1]+y.slmx[tp]);
    res.smx[tp] = max(res.smx[tp],x.srmx[tp]+y.lmx[tp]);
    }
    return res;
}
Node qry(int u,int l,int r){
    if(l==tr[u].l&&r==tr[u].r)
        return tr[u];
    pushdown(u);
    int mid = (tr[u].l+tr[u].r)/2;
    if(r<=mid) return qry(u*2,l,r);
    else if(l>mid) return qry(u*2+1,l,r);
    else return pushupn(qry(u*2,l,mid),qry(u*2+1,mid+1,r));
}
int main(){
    scanf("%d%d",&n,&q);
    cin >> (s+1);
    for(int i = 1;i<=n;i++){
        if(s[i]=='<') a[i] = 1;
        else a[i] = 0;
    }
    bt(1,1,n,0);
    bt(1,1,n,1);
    for(int i = 1;i<=q;i++){
        int l,r;
        scanf("%d%d",&l,&r);
        chg(1,l,r);
        Node res = qry(1,l,r);
        printf("%d\n",max(res.mx[1],max(res.smx[1],res.mx[0])));
    }
    return 0;
}


// CF 1371 F
#include<bits/stdc++.h>
using namespace std;
const int N = 5e5 + 7;
int n,q;
char s[N];
int a[N] = {0};
struct Node{
    int l,r;
    int lmx[2],rmx[2],mx[2];
    int slmx[2],srmx[2],smx[2];
    bool rev;
}tr[N*4];
void pushup(int u,int tp){
    tr[u].lmx[tp] = tr[u*2].lmx[tp];
    if(tr[u*2].lmx[tp] == tr[u*2].r-tr[u*2].l+1)
        tr[u].lmx[tp] = tr[u*2].lmx[tp] + tr[u*2+1].lmx[tp];
    tr[u].rmx[tp] = tr[u*2+1].rmx[tp];
    if(tr[u*2+1].rmx[tp] == tr[u*2+1].r-tr[u*2+1].l+1)
        tr[u].rmx[tp] = tr[u*2+1].rmx[tp] + tr[u*2].rmx[tp];
    tr[u].mx[tp] = max(tr[u*2].mx[tp],tr[u*2+1].mx[tp]);
    tr[u].mx[tp] = max(tr[u].mx[tp],tr[u*2].rmx[tp]+tr[u*2+1].lmx[tp]);
}
void pushup2(int u,int tp){
	tr[u].slmx[tp] = tr[u].lmx[tp],tr[u].srmx[tp] = tr[u].rmx[tp],tr[u].smx[tp] = tr[u].mx[tp];
	tr[u].slmx[tp] = max(tr[u].slmx[tp],max(tr[u*2+1].slmx[tp],tr[u*2].slmx[tp]));
    if(tr[u*2].slmx[tp] == tr[u*2].r-tr[u*2].l+1)
        tr[u].slmx[tp] = max(tr[u].slmx[tp],tr[u*2].slmx[tp] + tr[u*2+1].lmx[tp]);
    if(tr[u*2].lmx[tp^1] == tr[u*2].r-tr[u*2].l+1)
        tr[u].slmx[tp] = max(tr[u].slmx[tp],tr[u*2].lmx[tp^1] + tr[u*2+1].slmx[tp]);
    tr[u].srmx[tp] = max(tr[u].srmx[tp],max(tr[u*2].srmx[tp],tr[u*2+1].srmx[tp]));
    if(tr[u*2+1].srmx[tp] == tr[u*2+1].r-tr[u*2+1].l+1)
        tr[u].srmx[tp] = max(tr[u].srmx[tp],tr[u*2].rmx[tp^1] + tr[u*2+1].srmx[tp]);
    if(tr[u*2+1].rmx[tp] == tr[u*2+1].r-tr[u*2+1].l+1)
        tr[u].srmx[tp] = max(tr[u].srmx[tp],tr[u*2].srmx[tp] + tr[u*2+1].rmx[tp]);
    tr[u].smx[tp] = max(tr[u].smx[tp],max(tr[u*2].smx[tp],tr[u*2+1].smx[tp]));
    tr[u].smx[tp] = max(tr[u].smx[tp],tr[u*2].rmx[tp^1]+tr[u*2+1].slmx[tp]);
    tr[u].smx[tp] = max(tr[u].smx[tp],tr[u*2].srmx[tp]+tr[u*2+1].lmx[tp]);
}
void pushdown(int u){
    if(tr[u].rev){
        tr[u*2].rev ^= 1;
        swap(tr[u*2].mx[0],tr[u*2].mx[1]);
        swap(tr[u*2].smx[0],tr[u*2].smx[1]);
        swap(tr[u*2].lmx[0],tr[u*2].lmx[1]);
        swap(tr[u*2].rmx[0],tr[u*2].rmx[1]);
        swap(tr[u*2].slmx[0],tr[u*2].slmx[1]);
        swap(tr[u*2].srmx[0],tr[u*2].srmx[1]);
        tr[u*2+1].rev ^= 1;
        swap(tr[u*2+1].mx[0],tr[u*2+1].mx[1]);
        swap(tr[u*2+1].smx[0],tr[u*2+1].smx[1]);
        swap(tr[u*2+1].lmx[0],tr[u*2+1].lmx[1]);
        swap(tr[u*2+1].rmx[0],tr[u*2+1].rmx[1]);
        swap(tr[u*2+1].slmx[0],tr[u*2+1].slmx[1]);
        swap(tr[u*2+1].srmx[0],tr[u*2+1].srmx[1]);
        tr[u].rev = 0;
    }
}
void bt(int u,int l,int r,int tp){
    tr[u].l = l,tr[u].r = r;
    tr[u].rev = 0;
    if(l==r){
        if(!(a[l]^tp))tr[u].slmx[tp] = tr[u].srmx[tp] = tr[u].smx[tp] = tr[u].lmx[tp] = tr[u].rmx[tp] = tr[u].mx[tp] = 1;
        return;
    }
    int mid = (l+r)/2;
    bt(u*2,l,mid,tp);
    bt(u*2+1,mid+1,r,tp);
    pushup(u,tp);
    pushup2(u,tp);
}
void chg(int u,int l,int r){
    if(l<=tr[u].l&&r>=tr[u].r){
        swap(tr[u].mx[0],tr[u].mx[1]);
        swap(tr[u].smx[0],tr[u].smx[1]);
        swap(tr[u].lmx[0],tr[u].lmx[1]);
        swap(tr[u].rmx[0],tr[u].rmx[1]);
        swap(tr[u].slmx[0],tr[u].slmx[1]);
        swap(tr[u].srmx[0],tr[u].srmx[1]);
        tr[u].rev ^= 1;
        return;
    }
    pushdown(u);
    int mid = (tr[u].l+tr[u].r)/2;
    if(l<=mid) chg(u*2,l,r);
    if(r>mid) chg(u*2+1,l,r);
    pushup(u,0),pushup(u,1);
    pushup2(u,0),pushup2(u,1);
}
Node pushupn(Node x,Node y){
    Node res;
    res.l = x.l,res.r = y.r;
    res.rev = 0;
    for(int tp = 0;tp<2;tp++){
    res.lmx[tp] = x.lmx[tp];
    if(x.lmx[tp] == x.r-x.l+1)
        res.lmx[tp] = x.lmx[tp] + y.lmx[tp];
    res.rmx[tp] = y.rmx[tp];
    if(y.rmx[tp] == y.r-y.l+1)
        res.rmx[tp] = y.rmx[tp] + x.rmx[tp];
    res.mx[tp] = max(x.mx[tp],y.mx[tp]);
    res.mx[tp] = max(res.mx[tp],x.rmx[tp]+y.lmx[tp]);
    }
    for(int tp = 0;tp<2;tp++){
        res.slmx[tp] = res.lmx[tp],res.srmx[tp] = res.rmx[tp],res.smx[tp] = res.mx[tp];
	res.slmx[tp] = max(res.slmx[tp],max(x.slmx[tp],y.slmx[tp]));
    if(x.slmx[tp] == x.r-x.l+1)
        res.slmx[tp] = max(res.slmx[tp],x.slmx[tp] + y.lmx[tp]);
    if(x.lmx[tp^1] == x.r-x.l+1)
        res.slmx[tp] = max(res.slmx[tp],x.lmx[tp^1] + y.slmx[tp]);
    res.srmx[tp] = max(res.srmx[tp],max(x.srmx[tp],y.srmx[tp]));
    if(y.srmx[tp] == y.r-y.l+1)
        res.srmx[tp] = max(res.srmx[tp],x.rmx[tp^1] + y.srmx[tp]);
    if(y.rmx[tp] == y.r-y.l+1)
        res.srmx[tp] = max(res.srmx[tp],x.srmx[tp] + y.rmx[tp]);
    res.smx[tp] = max(res.smx[tp],max(x.smx[tp],y.smx[tp]));
    res.smx[tp] = max(res.smx[tp],x.rmx[tp^1]+y.slmx[tp]);
    res.smx[tp] = max(res.smx[tp],x.srmx[tp]+y.lmx[tp]);
    }
    return res;
}
Node qry(int u,int l,int r){
    if(l==tr[u].l&&r==tr[u].r)
        return tr[u];
    pushdown(u);
    int mid = (tr[u].l+tr[u].r)/2;
    if(r<=mid) return qry(u*2,l,r);
    else if(l>mid) return qry(u*2+1,l,r);
    else return pushupn(qry(u*2,l,mid),qry(u*2+1,mid+1,r));
}
int main(){
    scanf("%d%d",&n,&q);
    cin >> (s+1);
    for(int i = 1;i<=n;i++){
        if(s[i]=='<') a[i] = 1;
        else a[i] = 0;
    }
    bt(1,1,n,0);
    bt(1,1,n,1);
    for(int i = 1;i<=q;i++){
        int l,r;
        scanf("%d%d",&l,&r);
        chg(1,l,r);
        Node res = qry(1,l,r);
        printf("%d\n",max(res.mx[1],max(res.smx[1],res.mx[0])));
    }
    return 0;
}


#include<bits/stdc++.h> //:3
using namespace std;
typedef long long ll;
#define all(a) (a).begin(), (a).end()
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define rc(s) return cout<<s,0
#define pi pair <int, int>
#define sz(x) (int)((x).size())
#define int long long

const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};

const ll inf = 2e9;
const ll mod = 998244353;
const int N = 5e5 + 11;
const int NMAX = 3e2 + 11;
const ll INF64 = 3e18 + 1;
const double eps = 1e-14;
const double PI = acos(-1);

//ifstream in(".in");
//ofstream out(".out");

struct nod{
    int len;
    int mx[2], l[2], L[2], r[2], R[2];
};

int n, m, x, y;
string s;
vector<int>ans;
bool lazy[4*N];
nod t[4*N];

nod merge(nod a, nod b){

    nod cur;

    cur.len = a.len + b.len;

    for(int i = 0; i <= 1; i++){
        cur.l[i] = (a.l[i] == a.len ? a.len + b.l[i] : a.l[i]);
        cur.r[i] = (b.r[i] == b.len ? a.r[i] + b.len : b.r[i]);

        cur.L[i] = (a.r[i] == a.len ? a.len + b.L[i] : (a.L[i] == a.len ? a.len + b.l[i] : a.L[i]));
		cur.R[i] = (b.l[i] == b.len ? b.len + a.R[i] : (b.R[i] == b.len ? b.len + a.r[i] : b.R[i]));

        cur.mx[i] = max({a.mx[i], b.mx[i], a.r[i] + b.l[i], b.L[i] + a.r[i], a.R[i] + b.l[i]});
    }

    return cur;
}

void put(int v){
	lazy[v] ^= 1;
	swap(t[v].l[0], t[v].l[1]);
	swap(t[v].r[0], t[v].r[1]);
	swap(t[v].mx[0], t[v].mx[1]);
	swap(t[v].L[0], t[v].L[1]);
	swap(t[v].R[0], t[v].R[1]);
	return;
}

void push(int v, int l, int r){
	bool x = lazy[v];
	lazy[v] = 0;
	if(l == r || !x)return;
    put(v*2);
    put(v*2+1);
}

void build(int v, int l, int r){
    if(l == r){
        if(s[l] == '<'){
			t[v].l[0] = t[v].r[1] = 1, t[v].l[1] = t[v].r[0] = 0;
		}else{
			t[v].l[0] = t[v].r[1] = 0, t[v].l[1] = t[v].r[0] = 1;
		}

        t[v].mx[0] = t[v].mx[1] = 1;
		t[v].L[0] = t[v].L[1] = 1;
		t[v].R[0] = t[v].R[1] = 1;
		t[v].len = 1;
		return;
    }

    int mid = (l + r) >> 1;
    build(2*v, l, mid);
    build(2*v + 1, mid + 1, r);

    t[v] = merge(t[2*v], t[2*v + 1]);
}

void update(int v, int tl, int tr, int l, int r){
    if(tr < l || tl > r)return;

    if(l <= tl && tr <= r){
        put(v);
        return;
    }

    push(v, tl, tr);

    int mid = (tl + tr) >> 1;
    update(2*v, tl, mid, l, r);
    update(2*v + 1, mid + 1, tr, l, r);

    t[v] = merge(t[2*v], t[2*v + 1]);
}

void q(int v, int tl, int tr, int l, int r){
    if(tr < l || tl > r)return;

    if(l <= tl && tr <= r){
        ans.pb(v);
        return;
    }

    push(v, tl, tr);

    int mid = (tl + tr) >> 1;
    q(2*v, tl, mid, l, r);
    q(2*v + 1, mid + 1, tr, l, r);
}

void solve(){

    cin >> n >> m >> s; s = '.' + s;

    build(1, 1, n);

    while(m--){
        ans.clear();

        cin >> x >> y;

        update(1, 1, n, x, y);
        q(1, 1, n, x, y);

        nod hug = t[ans[0]];
        for(int i = 1; i < sz(ans); i++){
            hug = merge(hug, t[ans[i]]);
        }

        cout << hug.mx[0] << '\n';
    }

}

int32_t main(){
ios_base :: sync_with_stdio(0); cin.tie(0); cout.tie(0);

    //cout << setprecision(20) << fixed;

    int T = 1;
    //cin >> T;
    while(T--){
        solve();
    }
}


#include <bits/stdc++.h>
using namespace std;

const int Maxn = 1000005;
int n, m;
string str;
struct Tree
{
	int lt, rt, ll, lr, rl, rr, lmaxi1, lmaxi2, rmaxi1, rmaxi2, maxi1, maxi2;
	bool tag;
} tree[4 * Maxn];
Tree Swap(Tree x)
{
	swap(x.ll, x.lr), swap(x.rr, x.rl), swap(x.lmaxi1, x.lmaxi2), swap(x.rmaxi1, x.rmaxi2), swap(x.maxi1, x.maxi2);
	return x;
}
Tree merge(Tree x, Tree y)
{
	if (x.tag) x.tag = false, x = Swap(x);
	if (y.tag) y.tag = false, y = Swap(y);
	Tree ans;
	ans.tag = false;
	ans.lt = x.lt, ans.rt = y.rt;
	if (x.ll == x.rt - x.lt) ans.ll = x.ll + y.ll;
	else ans.ll = x.ll;
	if (y.rr == y.rt - y.lt) ans.rr = y.rr + x.rr;
	else ans.rr = y.rr;
	if (x.lr == x.rt - x.lt) ans.lr = x.lr + y.lr;
	else ans.lr = x.lr;
	if (y.rl == y.rt - y.lt) ans.rl = y.rl + x.rl;
	else ans.rl = y.rl;
	ans.maxi1 = max(x.maxi1, y.maxi1);
	ans.maxi1 = max(ans.maxi1, max(x.rr + y.lmaxi1, x.rmaxi1 + y.ll));
	ans.maxi2 = max(x.maxi2, y.maxi2);
	ans.maxi2 = max(ans.maxi2, max(x.rl + y.lmaxi2, x.rmaxi2 + y.lr));
	ans.lmaxi1 = max(x.lmaxi1 + (x.lmaxi1 == x.rt - x.lt) * y.ll, (x.lr == x.rt - x.lt) ? x.lr + y.lmaxi1 : 0);
	ans.rmaxi1 = max(y.rmaxi1 + (y.rmaxi1 == y.rt - y.lt) * x.rr, (y.rl == y.rt - y.lt) ? y.rl + x.rmaxi1 : 0);
	ans.lmaxi2 = max(x.lmaxi2 + (x.lmaxi2 == x.rt - x.lt) * y.lr, (x.ll == x.rt - x.lt) ? x.ll + y.lmaxi2 : 0);
	ans.rmaxi2 = max(y.rmaxi2 + (y.rmaxi2 == y.rt - y.lt) * x.rl, (y.rr == y.rt - y.lt) ? y.rr + x.rmaxi2 : 0);
	return ans;
}
void pushdown(int root)
{
	if (tree[root].tag)
	{
		tree[root].tag = 0;
		tree[root << 1].tag ^= 1, tree[root << 1 | 1].tag ^= 1;
		tree[root] = Swap(tree[root]);
	}
}
void build(int root, int lt, int rt)
{
	tree[root] = (Tree){lt, rt};
	if (lt + 1 == rt)
	{
		if (str[lt - 1] == '<') tree[root].ll = tree[root].rl = tree[root].maxi1 = tree[root].maxi2 = tree[root].lmaxi1 = tree[root].rmaxi2 = tree[root].rmaxi1 = tree[root].lmaxi2 = 1;
		else tree[root].lr = tree[root].rr = tree[root].maxi1 = tree[root].maxi2 = tree[root].lmaxi1 = tree[root].rmaxi2 = tree[root].rmaxi1 = tree[root].lmaxi2 = 1;
	}
	else
	{
		int mid = (lt + rt) >> 1;
		build(root << 1, lt, mid);
		build(root << 1 | 1, mid, rt);
		tree[root] = merge(tree[root << 1], tree[root << 1 | 1]);
	}
}
void modify(int root, int lt, int rt)
{
	if (lt == tree[root].lt && rt == tree[root].rt)
		tree[root].tag ^= 1;
	else
	{
		pushdown(root);
		int mid = (tree[root].lt + tree[root].rt) >> 1;
		if (lt >= mid) modify(root << 1 | 1, lt, rt);
		else if (rt <= mid) modify(root << 1, lt, rt);
		else modify(root << 1, lt, mid), modify(root << 1 | 1, mid, rt);
		tree[root] = merge(tree[root << 1], tree[root << 1 | 1]);
	}
}
Tree ask(int root, int lt, int rt)
{
	if (lt == tree[root].lt && rt == tree[root].rt)
	{
		pushdown(root);
		return tree[root];
	}
	else
	{
		pushdown(root);
		int mid = (tree[root].lt + tree[root].rt) >> 1;
		if (lt >= mid) return ask(root << 1 | 1, lt, rt);
		else if (rt <= mid) return ask(root << 1, lt, rt);
		else return merge(ask(root << 1, lt, mid), ask(root << 1 | 1, mid, rt));
	}
}
int main()
{
	scanf("%d%d", &n, &m);
	cin >> str;
	build(1, 1, n + 1);
	for (int i = 1; i <= m; i++)
	{
		int l, r;
		scanf("%d%d", &l, &r);
		modify(1, l, r + 1);
		Tree res = ask(1, l, r + 1);
		printf("%d\n", res.tag ? res.maxi2 : res.maxi1);
	}
	return 0;
}


#include <bits/stdc++.h>
#define maxn 500086

using namespace std;

struct Node{
	bool rev, id[2];
	bool sig[2], ld[2], rd[2];
	int l[2], r[2], m[2];
}t[maxn << 2];

#define ls(x) (x << 1)
#define rs(x) (x << 1 | 1)

inline Node up(Node x, Node y){
	Node z;
	z.rev = false;
	z.id[0] = 0, z.id[1] = 1;
	for(int k = 0;k <= 1;k++){
		int i = x.id[k], j = y.id[k];
		z.ld[k] = x.ld[i], z.rd[k] = y.rd[j];
		if(x.sig[i] && y.sig[j]){
			z.m[k] = 0;
			if(x.rd[i] == y.ld[j] || (x.rd[i] == 1 && y.ld[j] == 0)){
				z.sig[k] = true;
				z.l[k] = z.r[k] = x.l[i] + y.r[j];
			}else{
				z.sig[k] = false;
				z.l[k] = x.l[i], z.r[k] = y.r[j];
			}
		}else{
			if(x.sig[i]) x.r[i] = 0;
			else if(y.sig[j]) y.l[j] = 0;
			z.sig[k] = false;
			z.l[k] = x.l[i], z.r[k] = y.r[j];
			z.m[k] = max(x.m[i], y.m[j]);
			if(x.rd[i] == y.ld[j] || (x.rd[i] == 1 && y.ld[j] == 0)){
				if(x.sig[i]){
					z.l[k] = x.l[i] + y.l[j];
				}else if(y.sig[j]){
					z.r[k] = x.r[i] + y.r[j];
				}else{
					z.m[k] = max(z.m[k], x.r[i] + y.l[j]);
				}
			}else{
				z.m[k] = max(z.m[k], max(x.r[i], y.l[j]));
			}
		}
	}
	return z;
}

inline void reverse(int x){
	t[x].rev ^= 1;
	swap(t[x].id[0], t[x].id[1]);
}

inline void down(int x){
	if(t[x].rev){
		t[x].rev = false;
		reverse(ls(x)), reverse(rs(x));
	}
}

Node query(int x, int l, int r, int ll, int rr){
	if(ll <= l && r <= rr){
		reverse(x);
		//printf("%d %d %d %d %d--\n", l, r, t[x].l[0], t[x].r[0], t[x].sig[0]);
		return t[x];
	}
	int mid = l + r >> 1;
	Node node;
	if(mid >= rr) node = query(ls(x), l, mid, ll, rr);
	else if(mid < ll) node = query(rs(x), mid + 1, r, ll, rr);
	else node = up(query(ls(x), l, mid, ll, rr), query(rs(x), mid + 1, r, ll, rr));
	t[x] = up(t[ls(x)], t[rs(x)]);
	//printf("%d %d %d %d %d--\n", l, r, node.l[0], node.r[0], node.sig[0]);
	return node;
}

char s[maxn];

void build(int x, int l, int r){
	if(l == r){
		int i = s[l] == '>';
		t[x].rev = false;
		t[x].id[0] = 0, t[x].id[1] = 1;
		t[x].sig[0] = t[x].sig[1] = true;
		t[x].m[0] = t[x].m[1] = 0;

		t[x].ld[0] = t[x].rd[0] = i;
		t[x].l[0] = t[x].r[0] = 1;

		t[x].ld[1] = t[x].rd[1] = i ^ 1;
		t[x].l[1] = t[x].r[1] = 1;
		return;
	}
	int mid = l + r >> 1;
	build(ls(x), l, mid), build(rs(x), mid + 1, r);
	t[x] = up(t[ls(x)], t[rs(x)]);
	//printf("%d %d %d %d %d--\n", l, r, t[x].l[0], t[x].r[0], t[x].sig[0]);
}

int n, q;
int x, y;

int main(){
	scanf("%d%d%s", &n, &q, s + 1);
	build(1, 1, n);
	while(q--){

		scanf("%d%d", &x, &y);
		if(n == 500000){
			if(q == 99997){
				printf("%d %d--\n", x, y);
			}else{
				continue;
			}
		}

		Node node = query(1, 1, n, x, y);
		int i = node.id[0];
		printf("%d\n", max(node.m[i], max(node.l[i], node.r[i])));
	}
}


#include <bits/stdc++.h>
#define maxn 500086

using namespace std;

struct Node{
	bool rev, id[2];
	bool sig[2], ld[2], rd[2];
	int l[2], r[2], m[2];
}t[maxn << 2];

#define ls(x) (x << 1)
#define rs(x) (x << 1 | 1)

inline Node up(Node x, Node y){
	Node z;
	z.rev = false;
	z.id[0] = 0, z.id[1] = 1;
	for(int k = 0;k <= 1;k++){
		bool i = x.id[k], j = y.id[k];
		z.ld[k] = x.ld[i], z.rd[k] = y.rd[j];
		if(x.sig[i] && y.sig[j]){
			z.m[k] = 0;
			if(x.rd[i] == y.ld[j] || (x.rd[i] == 1 && y.ld[j] == 0)){
				z.sig[k] = true;
				z.l[k] = z.r[k] = x.l[i] + y.r[j];
			}else{
				z.sig[k] = false;
				z.l[k] = x.l[i], z.r[k] = y.r[j];
			}
		}else{
			if(x.sig[i]) x.r[i] = 0;
			else if(y.sig[j]) y.l[j] = 0;
			z.sig[k] = false;
			z.l[k] = x.l[i], z.r[k] = y.r[j];
			z.m[k] = max(x.m[i], y.m[j]);
			if(x.rd[i] == y.ld[j] || (x.rd[i] == 1 && y.ld[j] == 0)){
				if(x.sig[i]){
					z.l[k] = x.l[i] + y.l[j];
				}else if(y.sig[j]){
					z.r[k] = x.r[i] + y.r[j];
				}else{
					z.m[k] = max(z.m[k], x.r[i] + y.l[j]);
				}
			}else{
				z.m[k] = max(z.m[k], max(x.r[i], y.l[j]));
			}
		}
	}

	return z;
}

inline void reverse(int x){
	t[x].rev ^= 1;
	swap(t[x].id[0], t[x].id[1]);
}

inline void down(int x){
	if(t[x].rev){
		t[x].rev = false;
		reverse(ls(x)), reverse(rs(x));
	}
}

Node query(int x, int l, int r, int ll, int rr){
	if(ll <= l && r <= rr){
		reverse(x);
		//printf("%d %d %d %d %d--\n", l, r, t[x].l[0], t[x].r[0], t[x].sig[0]);
		return t[x];
	}
	int mid = l + r >> 1;
	Node node;
	if(mid >= rr) node = query(ls(x), l, mid, ll, rr);
	else if(mid < ll) node = query(rs(x), mid + 1, r, ll, rr);
	else node = up(query(ls(x), l, mid, ll, rr), query(rs(x), mid + 1, r, ll, rr));
	t[x] = up(t[ls(x)], t[rs(x)]);
	//printf("%d %d %d %d %d--\n", l, r, node.l[0], node.r[0], node.sig[0]);
	return node;
}

char s[maxn];

void build(int x, int l, int r){
	if(l == r){
		int i = s[l] == '>';
		t[x].rev = false;
		t[x].id[0] = 0, t[x].id[1] = 1;
		t[x].sig[0] = t[x].sig[1] = true;
		t[x].m[0] = t[x].m[1] = 0;

		t[x].ld[0] = t[x].rd[0] = i;
		t[x].l[0] = t[x].r[0] = 1;

		t[x].ld[1] = t[x].rd[1] = i ^ 1;
		t[x].l[1] = t[x].r[1] = 1;
		return;
	}
	int mid = l + r >> 1;
	build(ls(x), l, mid), build(rs(x), mid + 1, r);
	t[x] = up(t[ls(x)], t[rs(x)]);
	//printf("%d %d %d %d %d--\n", l, r, t[x].l[0], t[x].r[0], t[x].sig[0]);
}

int n, q;
int x, y;

int main(){
	scanf("%d%d%s", &n, &q, s + 1);
	build(1, 1, n);
	while(q--){
		scanf("%d%d", &x, &y);
		Node node = query(1, 1, n, x, y);
		int i = node.id[0];
		printf("%d\n", max(node.m[i], max(node.l[i], node.r[i])));
	}
}


import java.io.*;
import java.util.*;
import java.math.*;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class YetAnotherTetrisProblem {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskA solver = new TaskA();
        solver.solve(in.nextInt(), in, out);
        out.close();
    }
    static class TaskA {
        long mod = (long)(1000000007);
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            while(testNumber-->0){
            	int n = in.nextInt();
            	int a[] = new int[n];
            	int sum = 0;
            	for(int i=0;i<n;i++){
            		a[i] = in.nextInt();
            		if(a[i]==1)
            		sum ++;
            	}
            	if(sum%2==0)
            		out.println("YES");
            	else
            		out.println("NO");
            }
        }
        public void swap(int a[] , int p1 , int p2){
        	int x = a[p1];
        	a[p1] = a[p2];
        	a[p2] = x;
        }
        public void sortedArrayToBST(TreeSet<Integer> a , int start, int end) {
            if (start > end) {
                return;
            }
            int mid = (start + end) / 2;
            a.add(mid);
            sortedArrayToBST(a, start, mid - 1);
            sortedArrayToBST(a, mid + 1, end);
        }
        class Combine{
            int value;
            int delete;
            Combine(int val , int delete){
                this.value = val;
                this.delete = delete;
            }
        }
        class Sort2 implements Comparator<Combine>{
            public int compare(Combine a , Combine b){
                if(a.value > b.value)
                    return 1;
                else if(a.value == b.value && a.delete>b.delete)
                    return 1;
                else if(a.value == b.value && a.delete == b.delete)
                    return 0;
                return -1;
            }
        }
        public int lowerLastBound(ArrayList<Integer> a , int x){
            int l = 0;
            int r = a.size()-1;
            if(a.get(l)>=x)
                return -1;
            if(a.get(r)<x)
                return r;
            int mid = -1;
            while(l<=r){
                mid = (l+r)/2;
                if(a.get(mid) == x && a.get(mid-1)<x)
                    return mid-1;
                else if(a.get(mid)>=x)
                    r = mid-1;
                else if(a.get(mid)<x && a.get(mid+1)>=x)
                    return mid;
                else if(a.get(mid)<x && a.get(mid+1)<x)
                    l = mid+1;
            }
            return mid;
        }
        public int upperFirstBound(ArrayList<Integer> a , Integer x){
            int l = 0;
            int r = a.size()-1;
            if(a.get(l)>x)
                return l;
            if(a.get(r)<=x)
                return r+1;
            int mid = -1;
            while(l<=r){
                mid = (l+r)/2;
                if(a.get(mid) == x && a.get(mid+1)>x)
                    return mid+1;
                else if(a.get(mid)<=x)
                    l = mid+1;
                else if(a.get(mid)>x && a.get(mid-1)<=x)
                    return mid;
                else if(a.get(mid)>x && a.get(mid-1)>x)
                    r = mid-1;
            }
            return mid;
        }
        public int lowerLastBound(int a[] , int x){
            int l = 0;
            int r = a.length-1;
            if(a[l]>=x)
                return -1;
            if(a[r]<x)
                return r;
            int mid = -1;
            while(l<=r){
                mid = (l+r)/2;
                if(a[mid] == x && a[mid-1]<x)
                    return mid-1;
                else if(a[mid]>=x)
                    r = mid-1;
                else if(a[mid]<x && a[mid+1]>=x)
                    return mid;
                else if(a[mid]<x && a[mid+1]<x)
                    l = mid+1;
            }
            return mid;
        }
        public int upperFirstBound(long a[] , long x){
            int l = 0;
            int r = a.length-1;
            if(a[l]>x)
                return l;
            if(a[r]<=x)
                return r+1;
            int mid = -1;
            while(l<=r){
                mid = (l+r)/2;
                if(a[mid] == x && a[mid+1]>x)
                    return mid+1;
                else if(a[mid]<=x)
                    l = mid+1;
                else if(a[mid]>x && a[mid-1]<=x)
                    return mid;
                else if(a[mid]>x && a[mid-1]>x)
                    r = mid-1;
            }
            return mid;
        }
        public long log(float number , int base){
            return (long) Math.floor((Math.log(number) / Math.log(base)));
        }
        public long gcd(long a , long b){
            if(a<b){
                long c = b;
                b = a;
                a = c;
            }
            if(a%b==0)
                return b;
            return gcd(b , a%b);
        }
        public void print2d(long a[][] , PrintWriter out){
            for(int i=0;i<a.length;i++){
                for(int j=0;j<a[i].length;j++)
                    out.print(a[i][j] + " ");
                out.println();
            }
            out.println();
        }
        public void print1d(long a[] , PrintWriter out){
            for(int i=0;i<a.length;i++)
                out.print(a[i] + " ");
            out.println();
            out.println();
        }
    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

        public long nextLong() {
            return Long.parseLong(next());
        }

    }
}


import java.util.Scanner;

public class YetAnotherTetrisProblem {
    static int findMax(int[] A) {
        int max = A[0];
        for (int i =1; i < A.length; i++)
            max = Math.max(max, A[i]);
        return max;
    }
    static void solve(int[] A) {
        int max = findMax(A);
        int count = 0;

        for(int i = 0; i < A.length; i++){
            if(A[i] != max && (A[i] +2- max) == 0 )
                count++;
            if(A[i] == max)
                count++;
        }
        if(count == A.length )
            System.out.println("YES");
        else
            System.out.println("NO");
    }
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int T = sc.nextInt();
        while(T-->0) {
            int N = sc.nextInt();
            int[] A = new int[N];
            for(int i =0; i < N; i++) {
                A[i] =sc.nextInt();
            }
            solve(A);
        }
    }
}


import java.util.Scanner;

public class YetAnotherTetrisProblem {
    static void solve(int[] A) {
        //int max = findMax(A);
        int even = 0, odd=0;

        for(int i = 0; i < A.length; i++){
            if(A[i]%2==0)
                even++;
            else
                odd++;
        }
        if(even>0 && odd>0 )
            System.out.println("NO");
        else
            System.out.println("YES");
    }
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int T = sc.nextInt();
        while(T-->0) {
            int N = sc.nextInt();
            int[] A = new int[N];
            for(int i =0; i < N; i++) {
                A[i] =sc.nextInt();
            }
            solve(A);
        }
    }
}


import java.util.*;
import java.io.*;

public class Main{
	static FastScanner in;
	static PrintWriter out;
	public static void main(String[] args){
		in = new FastScanner(System.in);
		out = new PrintWriter(System.out);

		int T = in.nextInt();
		for (int t = 0; t < T; ++t){
			int n = in.nextInt();
			int even = 0;
			int odd  = 0;

			for (int i = 0; i < n; ++i){
				int h = in.nextInt();
				if (h % 2 == 0) {
					even++;
				} else {
					odd++;
				}
			}
			String ans = "NO";
			if (even == n || odd == n){
				ans = "YES";
			}
			out.println(ans);
		}
		out.close();

	}
	public static class FastScanner {
        private BufferedReader br;
        private StringTokenizer st;
        public FastScanner(InputStream inputStream){
            br = new BufferedReader(new InputStreamReader(inputStream));
        }
        public String nextLine() throws IOException {
            return br.readLine();
        }

        public String next() {
            while (st == null || !st.hasMoreTokens()){
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException ignored){}
            }
            return st.nextToken();
        }
        public int nextInt() {
            return Integer.parseInt(next());
        }
        public long nextLong() {
            return Long.parseLong(next());
        }
        public boolean nextBoolean() {
            return Boolean.parseBoolean(next());
        }
        public void close() throws IOException {
            br.close();
        }
    }
}


import java.io.*;
import java.util.*;

public class Main {
    static FastScanner in;
    static PrintWriter out;
    public static void main(String[] args) {
        in = new FastScanner(System.in);
        out = new PrintWriter(System.out);
        int t = in.nextInt();

        for (int i = 0; i < t; i++) {
            int n = in.nextInt();
            int[] h = new int[n];
            for (int j = 0; j < n; j++) {
                h[j] = in.nextInt();
            }
            int e =  h[0];
            boolean f = true;
            for (int j = 0; j < n; j++) {
                if (h[j] != h[0]){
                    f = false;
                    break;
                }
            }
            boolean f2 = true;
            for (int j = 0; j < n; j++) {
                for (int k = 0; k < n; k++) {
                    if (h[j] == h[k]  + 1) {
                        f2 = false;
                        break;
                    }
                }
            }

            String ans = "NO";

            if (f || f2) ans = "YES";
            out.println(ans);

        }
        out.close();
    }

    public static class FastScanner {
        private BufferedReader br;
        private StringTokenizer st;
        public FastScanner(InputStream inputStream){
            br = new BufferedReader(new InputStreamReader(inputStream));
        }
        public String nextLine() throws IOException {
            return br.readLine();
        }

        public String next() {
            while (st == null || !st.hasMoreTokens()){
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException ignored){}
            }
            return st.nextToken();
        }
        public int nextInt() {
            return Integer.parseInt(next());
        }
        public long nextLong() {
            return Long.parseLong(next());
        }
        public boolean nextBoolean() {
            return Boolean.parseBoolean(next());
        }
        public void close() throws IOException {
            br.close();
        }
    }
}


import java.io.*;
import java.util.*;

public class Main {
    static FastScanner in;
    static PrintWriter out;
    public static void main(String[] args) {
        in = new FastScanner(System.in);
        out = new PrintWriter(System.out);
        int t = in.nextInt();

        for (int i = 0; i < t; i++) {
            int n = in.nextInt();
            int mgap = 100;
            int p = -100;
            for (int j = 0; j < n; j++) {
                int a = in.nextInt();
                if (a-p != 0){
                    mgap = Math.min(mgap, Math.abs(a-p));
                }
                p = a;
            }
            String ans = "YES";
            if (mgap == 1) ans = "NO";
            out.println(ans);

        }
        out.close();
    }

    public static class FastScanner {
        private BufferedReader br;
        private StringTokenizer st;
        public FastScanner(InputStream inputStream){
            br = new BufferedReader(new InputStreamReader(inputStream));
        }
        public String nextLine() throws IOException {
            return br.readLine();
        }

        public String next() {
            while (st == null || !st.hasMoreTokens()){
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException ignored){}
            }
            return st.nextToken();
        }
        public int nextInt() {
            return Integer.parseInt(next());
        }
        public long nextLong() {
            return Long.parseLong(next());
        }
        public boolean nextBoolean() {
            return Boolean.parseBoolean(next());
        }
        public void close() throws IOException {
            br.close();
        }
    }
}


import java.util.*;
import java.io.*;

public class Main{
	static FastScanner in;
	static PrintWriter out;
	public static void main(String[] args){
		in = new FastScanner(System.in);
		out = new PrintWriter(System.out);

		int T = in.nextInt();
		for (int t = 0; t < T; ++t){
			int n = in.nextInt();

            int[] word = new int[n];
			for (int i = 0; i < n; ++i){
                word[i] = in.nextInt();
			}
            boolean found = false;
            for (int i = 0; i < n - 2; ++i){
                if (word[i] == word[i+2]) found = true;
            }

            if (!found){
                for (int i = 0; i < n-3; ++i){
                     if (word[i] == word[i+3] && word[i+1] == word[i+2]) found = true;
                }
            }

			String ans = "NO";
			if (found){
				ans = "YES";
			}
			out.println(ans);
		}
		out.close();

	}
	public static class FastScanner {
        private BufferedReader br;
        private StringTokenizer st;
        public FastScanner(InputStream inputStream){
            br = new BufferedReader(new InputStreamReader(inputStream));
        }
        public String nextLine() throws IOException {
            return br.readLine();
        }

        public String next() {
            while (st == null || !st.hasMoreTokens()){
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException ignored){}
            }
            return st.nextToken();
        }
        public int nextInt() {
            return Integer.parseInt(next());
        }
        public long nextLong() {
            return Long.parseLong(next());
        }
        public boolean nextBoolean() {
            return Boolean.parseBoolean(next());
        }
        public void close() throws IOException {
            br.close();
        }
    }
}


import java.io.BufferedWriter;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Comparator;
import java.util.InputMismatchException;
import java.util.Random;

public class CodeChefmarch1{

    static long x;
    static long y;
    static long dp[];

    public static void main(String[] args) {
        InputReader in = new InputReader();
        PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
        solve(in, out);
        out.close();
    }

    public static void solve(InputReader in, PrintWriter out) {

      int t=in.nextInt();

      for(int i=0;i<t;i++)
      {
          int n=in.nextInt();
          int m=in.nextInt();

          int type[]=new int[n];
          int price[]=new int[m+1];

          for(int j=0;j<n;j++)
          {
              type[j]=in.nextInt();

          }
          for(int j=0;j<n;j++)
          {

              price[type[j]]+=in.nextInt();

          }

          Arrays.sort(price);

          for(int k=1;k<=m;k++)
          {
              if(price[k]!=0)
              {
                  System.out.println(price[k]);
                  break;
              }
          }

      }

    }

    static class InputReader {
        private byte[] buf = new byte[16384];
        private int curChar;
        private int numChars;

        public int read() {
            if (numChars == -1)
                throw new InputMismatchException();
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = System.in.read(buf);

                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (numChars <= 0)
                    return -1;
            }
            return buf[curChar++];
        }

        public String nextLine() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            StringBuilder res = new StringBuilder();
            do {
                res.appendCodePoint(c);
                c = read();
            } while (!isEndOfLine(c));
            return res.toString();
        }

        public String nextString() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            StringBuilder res = new StringBuilder();
            do {
                res.appendCodePoint(c);
                c = read();
            } while (!isSpaceChar(c));
            return res.toString();
        }

        public long nextLong() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            long res = 0;
            do {
                if (c < '0' || c > '9')
                    throw new InputMismatchException();
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public int nextInt() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            int res = 0;
            do {
                if (c < '0' || c > '9')
                    throw new InputMismatchException();
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public int[] nextIntArray(int n) {
            int[] arr = new int[n];
            for (int i = 0; i < n; i++) {
                arr[i] = nextInt();
            }
            return arr;
        }

        public long[] nextLongArray(int n) {
            long[] arr = new long[n];
            for (int i = 0; i < n; i++) {
                arr[i] = nextLong();
            }
            return arr;
        }

        private boolean isSpaceChar(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        private boolean isEndOfLine(int c) {
            return c == '\n' || c == '\r' || c == -1;
        }
    }

}


import java.io.BufferedWriter;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Comparator;
import java.util.InputMismatchException;
import java.util.Random;

public class Problem1 {

    static long x;
    static long y;
    static long dp[];

    public static void main(String[] args) {
        InputReader in = new InputReader();
        PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
        solve(in, out);
        out.close();
    }

    public static void solve(InputReader in, PrintWriter out) {

        int t=in.nextInt();

        for(int i=0;i<t;i++)
        {
            boolean ispossible=true;
            int n=in.nextInt();
            int first=in.nextInt();
            for(int j=1;j<n;j++)
            {
                int value=in.nextInt();
                if(!(Math.abs(value-first)%2==0||value-first==0))
                    ispossible=false;

            }
            if(ispossible)
                System.out.println("YES");
            else System.out.println("NO");
        }

    }

    static class InputReader {
        private byte[] buf = new byte[16384];
        private int curChar;
        private int numChars;

        public int read() {
            if (numChars == -1)
                throw new InputMismatchException();
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = System.in.read(buf);

                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (numChars <= 0)
                    return -1;
            }
            return buf[curChar++];
        }

        public String nextLine() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            StringBuilder res = new StringBuilder();
            do {
                res.appendCodePoint(c);
                c = read();
            } while (!isEndOfLine(c));
            return res.toString();
        }

        public String nextString() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            StringBuilder res = new StringBuilder();
            do {
                res.appendCodePoint(c);
                c = read();
            } while (!isSpaceChar(c));
            return res.toString();
        }

        public long nextLong() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            long res = 0;
            do {
                if (c < '0' || c > '9')
                    throw new InputMismatchException();
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public int nextInt() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            int res = 0;
            do {
                if (c < '0' || c > '9')
                    throw new InputMismatchException();
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public int[] nextIntArray(int n) {
            int[] arr = new int[n];
            for (int i = 0; i < n; i++) {
                arr[i] = nextInt();
            }
            return arr;
        }

        public long[] nextLongArray(int n) {
            long[] arr = new long[n];
            for (int i = 0; i < n; i++) {
                arr[i] = nextLong();
            }
            return arr;
        }

        private boolean isSpaceChar(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        private boolean isEndOfLine(int c) {
            return c == '\n' || c == '\r' || c == -1;
        }
    }

}


import java.util.*;

public class DIV3A {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int t = sc.nextInt();
        for (int cas = 0; cas < t; cas++) {
            int n = sc.nextInt();
            int[] a = new int[n];
            for (int i = 1; i < n; i++) {
                a[i] = sc.nextInt();
            }
            a[0] = sc.nextInt();
            int ch = a[0] % 2;
            boolean chet = true;
            for (int i = 1; i < n; i++) {
                if (ch != a[i] % 2) {
                    System.out.println("NO");
                    chet = false;
                }
            }
            if (chet)  {
                System.out.println("YES");
            }
        }
    }
}


import java.util.*;

public class DIV3A {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int t = sc.nextInt();
        for (int cas = 0; cas < t; cas++) {
            int n = sc.nextInt();
            int[] a = new int[n];
            a[0] = sc.nextInt();
            for (int i = 1; i < n; i++) {
                a[i] = sc.nextInt();
            }
            int ch = a[0] % 2;
            boolean chet = true;
            for (int i = 1; i < n; i++) {
                if (ch != a[i] % 2) {
                    System.out.println("NO");
                    chet = false;
                    break;
                }
            }
            if (chet)  {
                System.out.println("YES");
            }
        }
    }
}


import java.util.*;

public class DIV3A {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int t = sc.nextInt();
        for (int cas = 0; cas < t; cas++) {
            int n = sc.nextInt();
            int[] a = new int[n];
            a[0] = sc.nextInt();
            int ch = a[0] % 2;
            boolean che = true;
            for (int i = 1; i < n; i++) {
                a[i] = sc.nextInt();
                if (ch != a[i] % 2) {
                    System.out.println("NO");
                    che = false;
                }
            }
            if (che)  {
                System.out.println("YES");
            }
        }
    }
}


import java.util.*;
public class Solution{

public static void main(String[] args) {

		Scanner sc=new Scanner(System.in);
		int t=sc.nextInt();
		for(int i=0;i<t;i++) {
			int n=sc.nextInt();
			int[] arr=new int[n];
			int flag=0;
			//int ctr=0;
			for(int j=0;j<n;j++) {
				//System.out.println("_______");
				arr[j]=sc.nextInt();
				if(j>0) {
					int diff=Math.abs(arr[j]-arr[j-1]);
					if(diff % 2 != 0) {
						flag=1;
						//break;
					}
				}
			}
			//System.out.println("---------------------");
			if(flag==1) {
				System.out.println("NO");
			}else {
				System.out.println("YES");
			}
		}
	}
}


import java.util.*;
public class Solution{

public static void main(String[] args) {

		Scanner sc=new Scanner(System.in);
		int t=sc.nextInt();
		for(int i=0;i<t;i++) {
			int n=sc.nextInt();
			int[] arr=new int[n];
			int diff=0, flag=0;;
			//int ctr=0;
			for(int j=0;j<n;j++) {
				arr[j]=sc.nextInt();
				if(j>0) {
					diff=Math.abs(arr[j-1]-arr[j]);
					if(diff % 2 != 0) {
						flag=1;
						break;
					}
				}
			}
			if(flag==1) {
				System.out.println("NO");
			}else {
				System.out.println("YES");
			}
		}
	}
}


import java.io.*;
import java.util.Arrays;
import java.util.Scanner;

public class Main {

    private static final Scanner scanner = new Scanner(System.in);
    private static final BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    private static final BufferedWriter out = new BufferedWriter(new OutputStreamWriter(System.out));

    public static void main(String[] args) throws IOException {

        int T = Integer.parseInt(in.readLine());

        while (T-- > 0) {
            int n = Integer.parseInt(in.readLine());

            String[] aItems = in.readLine().split(" ");
            int[] A = new int[aItems.length];
            for (int i = 0; i < aItems.length; i++) {
                A[i] = Integer.parseInt(aItems[i]);
            }

            Arrays.sort(A);
            boolean isPossible = true;
            for (int i = 1; i < A.length; i++) {
                if (A[i] - A[i - 1] == 1) {
                    isPossible = false;
                }
            }

            if (isPossible) out.write("YES");
            else out.write("NO");

            out.newLine();
        }

        scanner.close();
        in.close();
        out.close();
    }

    static class Pair<T> {
        T first;
        T second;

        public Pair(T first, T second) {
            this.first = first;
            this.second = second;
        }

        public T getFirst() {
            return this.first;
        }

        public T getSecond() {
            return this.second;
        }

    }
}


import java.io.*;
import java.util.Arrays;
import java.util.Scanner;

public class Main {

    private static final Scanner scanner = new Scanner(System.in);
    private static final BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    private static final BufferedWriter out = new BufferedWriter(new OutputStreamWriter(System.out));

    public static void main(String[] args) throws IOException {

        int T = Integer.parseInt(in.readLine());

        while (T-- > 0) {
            int n = Integer.parseInt(in.readLine());

            String[] aItems = in.readLine().split(" ");
            int[] A = new int[aItems.length];
            for (int i = 0; i < aItems.length; i++) {
                A[i] = Integer.parseInt(aItems[i]);
            }

            Arrays.sort(A);
            boolean isPossible = true;
            for (int i = 1; i < A.length; i++) {
                if ((A[i] - A[i - 1]) % 2 != 0) {
                    isPossible = false;
                }
            }

            if (isPossible) out.write("YES");
            else out.write("NO");

            out.newLine();
        }

        scanner.close();
        in.close();
        out.close();
    }

    static class Pair<T> {
        T first;
        T second;

        public Pair(T first, T second) {
            this.first = first;
            this.second = second;
        }

        public T getFirst() {
            return this.first;
        }

        public T getSecond() {
            return this.second;
        }

    }
}


import java.util.*;
import java.io.*;
import java.text.*;

public class cf1324a {
    public static FastReader in;
    public static int T;
    public static void main(String[] args) {
        // write your code here
        in = new FastReader();
        T = in.nextInt();
        for(int cas = 1; cas <= T; cas++) {
            int n = in.nextInt();
            int[] b = new int[n + 1];
            for (int i = 1; i <= n; i++) {
                b[i] = in.nextInt();
            }
            boolean flag = false;
            for (int i = 1; i <= n; i++) {
                if (((b[i] ^ b[1]) & 1) == 1) {
                    flag = true;
                    break;
                }
            }
            if (flag == false) System.out.println("yes");
            else System.out.println("no");
        }
    }
    static class FastReader {
        BufferedReader br;
        StringTokenizer st;
        public FastReader() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }
        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }
        int nextInt() {
            return Integer.parseInt(next());
        }
        long nextLong() {
            return Long.parseLong(next());
        }
        double nextDouble() {
            return Double.parseDouble(next());
        }
        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
    }
}


import java.util.*;
import java.io.*;
import java.text.*;

public class cf1324a {
    public static FastReader in;
    public static int T;
    public static int[][] a;
    public static void main(String[] args) {
        // write your code here
        in = new FastReader();
        T = in.nextInt();
        a = new int[111][111];

        for(int cas = 1; cas <= T; cas++) {
            int n = in.nextInt();
            int[] b = new int[n + 1];
            for (int i = 1; i <= n; i++){
                for (int j = 0; j < 111; j++) {
                    a[i][j] = 0;
                }
            }
            int max_value = -1;
            for (int i = 1; i <= n; i++) {
                b[i] = in.nextInt();
                max_value = Math.max(b[i], max_value);
                for (int j = 1; j <= b[i]; j++) {
                    a[i][j] = 1;
                }
            }
            boolean flag = false;
            for (int col = 1; col <= max_value; col++) {
                for (int i = 1; i <= n; i++) {
                    if (a[i][col] == 0) {
                        if (a[i + 1][col] == 1 || i + 1 > n) flag = true;
                        else i = i + 1;
                    }
                }
            }
            if (flag == true) System.out.println("No");
            else System.out.println("yes");
        }
    }
    static class FastReader {
        BufferedReader br;
        StringTokenizer st;
        public FastReader() {
            br = new BufferedReader(new
                    InputStreamReader(System.in));
        }
        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }
        int nextInt() {
            return Integer.parseInt(next());
        }
        long nextLong() {
            return Long.parseLong(next());
        }
        double nextDouble() {
            return Double.parseDouble(next());
        }
        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
    }
}


import java.io.IOException;
import java.io.InputStream;

public class YetAnotherTetrisProblem {

	public static void main(String[] args) throws IOException {
		FastReader in=new FastReader(System.in);
		int t=in.nextInt();
		while(t>0){
			--t;
			int n=in.nextInt();
			int evencount=0;
			int oddcount=0;
			for(int i=0;i<n;i++){
				int a=in.nextInt();
				if(a%2==0)
					++evencount;
				else
					++oddcount;
			}
			if(oddcount==0 && evencount==n)
				System.out.println("YES");
			else if(evencount==0 && oddcount==n)
				System.out.println("YES");
			else
				System.out.println("NO");
		}

	}

}

class FastReader {

    byte[] buf = new byte[2048];
    int index, total;
    InputStream in;

    FastReader(InputStream is) {
        in = is;
    }

    int scan() throws IOException {
        if (index >= total) {
            index = 0;
            total = in.read(buf);
            if (total <= 0) {
                return -1;
            }
        }
        return buf[index++];
    }

    String next() throws IOException {
        int c;
        for (c = scan(); c <= 32; c = scan()) ;
        StringBuilder sb = new StringBuilder();
        for (; c > 32; c = scan()) {
            sb.append((char) c);
        }
        return sb.toString();
    }

    String nextLine() throws IOException {
        int c;
        for (c = scan(); c <= 32; c = scan()) ;
        StringBuilder sb = new StringBuilder();
        for (; c != 10 && c != 13; c = scan()) {
            sb.append((char) c);
        }
        return sb.toString();
    }

    char nextChar() throws IOException {
        int c;
        for (c = scan(); c <= 32; c = scan()) ;
        return (char) c;
    }

    int nextInt() throws IOException {
        int c, val = 0;
        for (c = scan(); c <= 32; c = scan()) ;
        boolean neg = c == '-';
        if (c == '-' || c == '+') {
            c = scan();
        }
        for (; c >= '0' && c <= '9'; c = scan()) {
            val = (val << 3) + (val << 1) + (c & 15);
        }
        return neg ? -val : val;
    }

    long nextLong() throws IOException {
        int c;
        long val = 0;
        for (c = scan(); c <= 32; c = scan()) ;
        boolean neg = c == '-';
        if (c == '-' || c == '+') {
            c = scan();
        }
        for (; c >= '0' && c <= '9'; c = scan()) {
            val = (val << 3) + (val << 1) + (c & 15);
        }
        return neg ? -val : val;
    }
}


mport java.io.IOException;
import java.io.InputStream;

public class YetAnotherTetrisProblem {

	public static void main(String[] args) throws IOException {
		FastReader in=new FastReader(System.in);
		int t=in.nextInt();
		while(t>0){
			--t;
			int n=in.nextInt();
			int evencount=0;
			int oddcount=0;
			for(int i=0;i<n;i++){
				int a=in.nextInt();
				if(a%2==0)
					++evencount;
				else
					++oddcount;
			}
			if(oddcount==0 && evencount==n)
				System.out.println("YES");
			else if(evencount==0 && oddcount==n)
				System.out.println("YES");
			else
				System.out.println("NO");
		}

	}

}

class FastReader {

    byte[] buf = new byte[2048];
    int index, total;
    InputStream in;

    FastReader(InputStream is) {
        in = is;
    }

    int scan() throws IOException {
        if (index >= total) {
            index = 0;
            total = in.read(buf);
            if (total <= 0) {
                return -1;
            }
        }
        return buf[index++];
    }

    String next() throws IOException {
        int c;
        for (c = scan(); c <= 32; c = scan()) ;
        StringBuilder sb = new StringBuilder();
        for (; c > 32; c = scan()) {
            sb.append((char) c);
        }
        return sb.toString();
    }

    String nextLine() throws IOException {
        int c;
        for (c = scan(); c <= 32; c = scan()) ;
        StringBuilder sb = new StringBuilder();
        for (; c != 10 && c != 13; c = scan()) {
            sb.append((char) c);
        }
        return sb.toString();
    }

    char nextChar() throws IOException {
        int c;
        for (c = scan(); c <= 32; c = scan()) ;
        return (char) c;
    }

    int nextInt() throws IOException {
        int c, val = 0;
        for (c = scan(); c <= 32; c = scan()) ;
        boolean neg = c == '-';
        if (c == '-' || c == '+') {
            c = scan();
        }
        for (; c >= '0' && c <= '9'; c = scan()) {
            val = (val << 3) + (val << 1) + (c & 15);
        }
        return neg ? -val : val;
    }

    long nextLong() throws IOException {
        int c;
        long val = 0;
        for (c = scan(); c <= 32; c = scan()) ;
        boolean neg = c == '-';
        if (c == '-' || c == '+') {
            c = scan();
        }
        for (; c >= '0' && c <= '9'; c = scan()) {
            val = (val << 3) + (val << 1) + (c & 15);
        }
        return neg ? -val : val;
    }
}


import java.util.Scanner;
public class Codeforce_1324A {
    public static void main(String[] args) {

        int number;
        long a;
        long b;
        long c = 0;

        Scanner in = new Scanner(System.in);
        number = in.nextInt();

        for (int i = 0; i < number; i++) {
            a = in.nextLong();
            for (int j = 0; j < a; j++) {
                b = in.nextLong();
                if (b % 2 == 0) {
                    c++;
                }
            }
            if (c == a || c == 0) {
                System.out.println("yes");
            } else {
                System.out.println("no");
            }
        }
    }
}