#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define mp make_pair
#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()
#define yn(x) ((x) ? "Yes" : "No")
#define rep(i, l, r) for (int i = (int)(l); i <= (int)(r); i++)
#define per(i, r, l) for (int i = (int)(r); i >= (int)(l); i--)
typedef long long ll;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
template <typename _Tp> bool maximize(_Tp &__a, const _Tp &__b) { if (__a < __b) { __a = __b; return true; } return false; }
template <typename _Tp> bool minimize(_Tp &__a, const _Tp &__b) { if (__a > __b) { __a = __b; return true; } return false; }
const int siz = 2e5 + 2;
const int SIZ = 1e6 + 2;
const int mod = 1e9 + 7;
const int maxx = 2e9;
const ll MAXX = 1e18;
const string file = "3";
mt19937 mt_rng_32(chrono::steady_clock::now().time_since_epoch().count());
int rand_int(int lt, int rt) {
assert(lt <= rt);
return uniform_int_distribution <int> (lt, rt) (mt_rng_32);
}
struct implicit_treap {
struct node {
int lch, rch, pry, cnt, val;
node(int val = 0) : lch(0), rch(0), pry(rand_int(1, 1e9)), cnt(0), val(val) {
}
};
int root, len;
vector <node> tree;
implicit_treap() : root(0), len(0) {
tree.assign(1, node());
}
void recompute(int nd) {
if (nd) {
tree[nd].cnt = 1 + tree[tree[nd].lch].cnt + tree[tree[nd].rch].cnt;
}
}
void split(int crt, int key, int &lrt, int &rrt, int add = 0) {
if (!crt) {
lrt = rrt = 0;
} else {
int implicit_key = add + tree[tree[crt].lch].cnt;
if (key <= implicit_key) {
split(tree[crt].lch, key, lrt, tree[crt].lch, add);
rrt = crt;
} else {
split(tree[crt].rch, key, tree[crt].rch, rrt, implicit_key + 1);
lrt = crt;
}
}
recompute(crt);
}
void merge(int lrt, int rrt, int &crt) {
if (!lrt || !rrt) {
crt = (lrt) ? lrt : rrt;
} else if (tree[lrt].pry > tree[rrt].pry) {
merge(tree[lrt].rch, rrt, tree[lrt].rch);
crt = lrt;
} else {
merge(lrt, tree[rrt].lch, tree[rrt].lch);
crt = rrt;
}
recompute(crt);
}
template <typename _Tp>
void extract(ostream &stream, string fill, int crt) {
if (!crt) {
return;
}
extract <_Tp> (stream, fill, tree[crt].lch);
stream << _Tp(tree[crt].val) << fill;
extract <_Tp> (stream, fill, tree[crt].rch);
}
int new_node(int val) {
tree.push_back(val);
return sz(tree) - 1;
}
void insert(int pos, int val) {
assert(1 <= pos && pos <= len + 1);
int lrt, rrt;
split(root, pos - 1, lrt, rrt);
merge(lrt, new_node(val), lrt);
merge(lrt, rrt, root);
len++;
}
void rotate(int lt, int rt, int num) {
assert(1 <= lt && lt <= rt && rt <= len);
int lrt, mrt, rrt, trt;
split(root, lt - 1, lrt, mrt);
split(mrt, rt - lt + 1, mrt, rrt);
num %= tree[mrt].cnt;
split(mrt, tree[mrt].cnt - num, mrt, trt);
merge(lrt, trt, root);
merge(root, mrt, root);
merge(root, rrt, root);
}
void move(int lt, int rt, int pos) {
assert(1 <= lt && lt <= rt && rt <= len && 1 <= pos && pos <= len - (rt - lt + 1) + 1);
if (pos <= lt) {
rotate(pos, rt, rt - lt + 1);
} else {
rotate(lt, pos + (rt - lt + 1) - 1, pos - lt);
}
}
template <typename _Tp = int>
void extract(ostream &stream, string fill = " ") {
extract <_Tp> (stream, fill, root);
stream << "\n";
}
};
signed main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n, q; string s;
cin >> n >> q >> s;
s = ' ' + s;
implicit_treap tree;
rep (i, 1, n) {
tree.insert(i, s[i]);
}
while (q--) {
int l, r;
cin >> l >> r;
tree.move(l, r, n - (r - l + 1) + 1);
}
tree.extract <char> (cout, "");
return 0;
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CnVzaW5nIG5hbWVzcGFjZSBzdGQ7CiNkZWZpbmUgZmkgZmlyc3QKI2RlZmluZSBzZSBzZWNvbmQKI2RlZmluZSBtcCBtYWtlX3BhaXIKI2RlZmluZSBzeih4KSAoaW50KSh4KS5zaXplKCkKI2RlZmluZSBhbGw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GludD4gKGx0LCBydCkgKG10X3JuZ18zMik7Cn0Kc3RydWN0IGltcGxpY2l0X3RyZWFwIHsKICAgIHN0cnVjdCBub2RlIHsKICAgICAgICBpbnQgbGNoLCByY2gsIHByeSwgY250LCB2YWw7CiAgICAgICAgbm9kZShpbnQgdmFsID0gMCkgOiBsY2goMCksIHJjaCgwKSwgcHJ5KHJhbmRfaW50KDEsIDFlOSkpLCBjbnQoMCksIHZhbCh2YWwpIHsKICAgICAgICB9CiAgICB9OwogICAgaW50IHJvb3QsIGxlbjsKICAgIHZlY3RvciA8bm9kZT4gdHJlZTsKICAgIGltcGxpY2l0X3RyZWFwKCkgOiByb290KDApLCBsZW4oMCkgewogICAgICAgIHRyZWUuYXNzaWduKDEsIG5vZGUoKSk7CiAgICB9CiAgICB2b2lkIHJlY29tcHV0ZShpbnQgbmQpIHsKICAgICAgICBpZiAobmQpIHsKICAgICAgICAgICAgdHJlZVtuZF0uY250ID0gMSArIHRyZWVbdHJlZVtuZF0ubGNoXS5jbnQgKyB0cmVlW3RyZWVbbmRdLnJjaF0uY250OwogICAgICAgIH0KICAgIH0KICAgIHZvaWQgc3BsaXQoaW50IGNydCwgaW50IGtleSwgaW50ICZscnQsIGludCAmcnJ0LCBpbnQgYWRkID0gMCkgewogICAgICAgIGlmICghY3J0KSB7CiAgICAgICAgICAgIGxydCA9IHJydCA9IDA7CiAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgaW50IGltcGxpY2l0X2tleSA9IGFkZCArIHRyZWVbdHJlZVtjcnRdLmxjaF0uY250OwogICAgICAgICAgICBpZiAoa2V5IDw9IGltcGxpY2l0X2tleSkgewogICAgICAgICAgICAgICAgc3BsaXQodHJlZVtjcnRdLmxjaCwga2V5LCBscnQsIHRyZWVbY3J0XS5sY2gsIGFkZCk7CiAgICAgICAgICAgICAgICBycnQgPSBjcnQ7CiAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgICBzcGxpdCh0cmVlW2NydF0ucmNoLCBrZXksIHRyZWVbY3J0XS5yY2gsIHJydCwgaW1wbGljaXRfa2V5ICsgMSk7CiAgICAgICAgICAgICAgICBscnQgPSBjcnQ7CiAgICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgcmVjb21wdXRlKGNydCk7CiAgICB9CiAgICB2b2lkIG1lcmdlKGludCBscnQsIGludCBycnQsIGludCAmY3J0KSB7CiAgICAgICAgaWYgKCFscnQgfHwgIXJydCkgewogICAgICAgICAgICBjcnQgPSAobHJ0KSA/IGxydCA6IHJydDsKICAgICAgICB9IGVsc2UgaWYgKHRyZWVbbHJ0XS5wcnkgPiB0cmVlW3JydF0ucHJ5KSB7CiAgICAgICAgICAgIG1lcmdlKHRyZWVbbHJ0XS5yY2gsIHJydCwgdHJlZVtscnRdLnJjaCk7CiAgICAgICAgICAgIGNydCA9IGxydDsKICAgICAgICB9IGVsc2UgewogICAgICAgICAgICBtZXJnZShscnQsIHRyZWVbcnJ0XS5sY2gsIHRyZWVbcnJ0XS5sY2gpOwogICAgICAgICAgICBjcnQgPSBycnQ7CiAgICAgICAgfQogICAgICAgIHJlY29tcHV0ZShjcnQpOwogICAgfQogICAgdGVtcGxhdGUgPHR5cGVuYW1lIF9UcD4KICAgIHZvaWQgZXh0cmFjdChvc3RyZWFtICZzdHJlYW0sIHN0cmluZyBmaWxsLCBpbnQgY3J0KSB7CiAgICAgICAgaWYgKCFjcnQpIHsKICAgICAgICAgICAgcmV0dXJuOwogICAgICAgIH0KICAgICAgICBleHRyYWN0IDxfVHA+IChzdHJlYW0sIGZpbGwsIHRyZWVbY3J0XS5sY2gpOwogICAgICAgIHN0cmVhbSA8PCBfVHAodHJlZVtjcnRdLnZhbCkgPDwgZmlsbDsKICAgICAgICBleHRyYWN0IDxfVHA+IChzdHJlYW0sIGZpbGwsIHRyZWVbY3J0XS5yY2gpOwogICAgfQogICAgaW50IG5ld19ub2RlKGludCB2YWwpIHsKICAgICAgICB0cmVlLnB1c2hfYmFjayh2YWwpOwogICAgIC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vcywgcnQsIHJ0IC0gbHQgKyAxKTsKICAgICAgICB9IGVsc2UgewogICAgICAgICAgICByb3RhdGUobHQsIHBvcyArIChydCAtIGx0ICsgMSkgLSAxLCBwb3MgLSBsdCk7CiAgICAgICAgfQogICAgfQogICAgdGVtcGxhdGUgPHR5cGVuYW1lIF9UcCA9IGludD4KICAgIHZvaWQgZXh0cmFjdChvc3RyZWFtICZzdHJlYW0sIHN0cmluZyBmaWxsID0gIiAiKSB7CiAgICAgICAgZXh0cmFjdCA8X1RwPiAoc3RyZWFtLCBmaWxsLCByb290KTsKICAgICAgICBzdHJlYW0gPDwgIlxuIjsKICAgIH0KfTsKc2lnbmVkIG1haW4oKSB7CiAgICBpb3M6OnN5bmNfd2l0aF9zdGRpbyhmYWxzZSk7CiAgICBjaW4udGllKG51bGxwdHIpOwogICAgaW50IG4sIHE7IHN0cmluZyBzOwogICAgY2luID4+IG4gPj4gcSA+PiBzOwogICAgcyA9ICcgJyArIHM7CiAgICBpbXBsaWNpdF90cmVhcCB0cmVlOwogICAgcmVwIChpLCAxLCBuKSB7CiAgICAgICAgdHJlZS5pbnNlcnQoaSwgc1tpXSk7CiAgICB9CiAgICB3aGlsZSAocS0tKSB7CiAgICAgICAgaW50IGwsIHI7CiAgICAgICAgY2luID4+IGwgPj4gcjsKICAgICAgICB0cmVlLm1vdmUobCwgciwgbiAtIChyIC0gbCArIDEpICsgMSk7CiAgICB9CiAgICB0cmVlLmV4dHJhY3QgPGNoYXI+IChjb3V0LCAiIik7CiAgICByZXR1cm4gMDsKfQo=