#include <bits/stdc++.h>
const int L = (int)3e6 + 5, N = 5005;
char s[L], ans[L];
int m, n, f[L], l[N], r[N], t[L];
void modify(int x) {
  for (; x <= m; x += x & -x) t[x]--;
}
int kth(int k) {
  int x = 0;
  for (int b = 1 << 21; b; b >>= 1)
    if (x + b <= m && t[x + b] < k) k -= t[x += b];
  return x + 1;
}
int main() {
  scanf("%s%d%d", s + 1, &m, &n);
  for (int tim = 1; tim <= n; tim++) scanf("%d%d", &l[tim], &r[tim]);
  for (int i = 1; i <= m; i++) t[i] = i & -i;
  for (int tim = n; tim >= 1; tim--) {
    for (int i = l[tim] + 1; i <= r[tim]; i += 2) {
      int loc = kth(r[tim] + 1);
      if (loc > m) break;
      f[loc] = kth(i);
      modify(loc);
    }
    for (int i = l[tim]; i <= r[tim]; i += 2) {
      int loc = kth(r[tim] + 1);
      if (loc > m) break;
      f[loc] = kth(i);
      modify(loc);
    }
  }
  for (int i = 1, loc; (loc = kth(i)) <= m; i++) ans[loc] = s[i];
  for (int i = 1; i <= m; i++)
    if (f[i]) ans[i] = ans[f[i]];
  puts(ans + 1);
}
