#include <bits/stdc++.h>
using namespace std;
struct aaa {
  int x, y;
} a[3000010];
int n, m, f[3000010], b[3000010];
char s[3000010], ans[3000010];
int lowbit(int x) { return x & (-x); }
void ins(int x, int t) {
  int i;
  for (i = x; i <= n; i += lowbit(i)) f[i] += t;
}
int get(int x) {
  int i, hh, l = log2(n), sz = 0, now = 0;
  for (i = l; i >= 0; i--) {
    hh = 1 << i;
    if (now + hh <= n && sz + f[now + hh] < x) {
      sz += f[now + hh];
      now += hh;
    }
  }
  return now + 1;
}
int main() {
  int i, j, x, now, po;
  scanf("%s", s + 1);
  scanf("%d", &n);
  scanf("%d", &m);
  for (i = 1; i <= m; i++) scanf("%d%d", &a[i].x, &a[i].y);
  for (i = 1; i <= n; i++) f[i] = i & (-i);
  now = n;
  for (i = m; i; i--) {
    for (j = 1, x = a[i].x + 1; a[i].y < now && j <= a[i].y - a[i].x + 1;
         j++, x += 2, now--) {
      if (x > a[i].y) x = a[i].x;
      po = get(a[i].y + 1);
      ins(po, -1);
      b[po] = get(x);
    }
  }
  for (i = 1, j = 0; i <= n; i++)
    if (b[i])
      ans[i] = ans[b[i]];
    else
      ans[i] = s[++j];
  puts(ans + 1);
}
