#include <bits/stdc++.h>
using namespace std;
int T[15000000];
char ch[3333000], ans[3333000];
struct Node {
  int x, y;
} A[5100];
int N, K;
int F[3333000];
inline void buildTree(int node, int l, int r) {
  if (l + 1 == r) {
    T[node] = 1;
    return;
  }
  int mid = (l + r) >> 1;
  buildTree(((node) << 1), l, mid);
  buildTree((((node) << 1) | 1), mid, r);
  T[node] = r - l;
  return;
}
inline int Query(int node, int l, int r, int pos) {
  if (l + 1 == r) {
    return l;
  }
  int mid = (l + r) >> 1;
  if (pos <= T[((node) << 1)]) {
    return Query(((node) << 1), l, mid, pos);
  } else {
    return Query((((node) << 1) | 1), mid, r, pos - T[((node) << 1)]);
  }
}
inline void remove(int node, int l, int r, int pos) {
  if (l + 1 == r) {
    T[node]--;
    return;
  }
  int mid = (l + r) >> 1;
  if (pos < mid) {
    remove(((node) << 1), l, mid, pos);
  } else {
    remove((((node) << 1) | 1), mid, r, pos);
  }
  T[node]--;
}
int main(int argc, char *argv[]) {
  scanf("%s", ch);
  scanf("%d%d", &K, &N);
  for (int i = 0; i < N; i++) {
    scanf("%d%d", &A[i].x, &A[i].y);
  }
  buildTree(1, 1, K + 1);
  for (int i = N - 1; i >= 0; i--)
    if (A[i].y < T[1]) {
      int Len = A[i].y - A[i].x + 1;
      int now = A[i].x + 1;
      if (now > A[i].y) {
        now = A[i].x;
      }
      for (int j = 1; j <= Len && A[i].y < T[1]; j++) {
        int k = Query(1, 1, K + 1, A[i].y + 1);
        remove(1, 1, K + 1, k);
        F[k] = Query(1, 1, K + 1, now);
        now += 2;
        if (now > A[i].y) {
          now = A[i].x;
        }
      }
    }
  int j = 0;
  for (int i = 0; i < K; i++)
    if (F[i + 1] == 0) {
      ans[i] = ch[j++];
    } else {
      ans[i] = ans[F[i + 1] - 1];
    }
  printf("%s\n", ans);
  return 0;
}
