CSES - Shared codeLink to this code: https://cses.fi/paste/5f59f9d91a30b1823efeda/
#include <iostream>
#include <ext/rope>

const bool debug = false;

using namespace std;
using namespace __gnu_cxx;

void setI(string filename) {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    freopen(filename.c_str(), "r", stdin);
    //freopen(filename.c_str(), "w", stdout);
}

void setO(string filename) {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    // freopen(filename.c_str(), "r", stdin);
    freopen(filename.c_str(), "w", stdout);
}
crope letters;
string x;
int n,m;
int main() {
    if (debug) {
        setI("test.txt");
    } else {
        ios_base::sync_with_stdio(0);
        cin.tie(0);
        cout.tie(0);
    }
    cin>>n>>m;
    cin>>x;
    for(char a:x){
        letters.push_back(a);
    }
    for(int i=0;i<m;i++){
        int a,b;
        cin>>a>>b;
        a--;b--;
        auto target=letters.substr(a,b-a+1);
        letters.erase(a,b-a+1);
        letters+=target;
    }
    cout<<letters<<"\n";
}