#include <bits/stdc++.h>
char S[3000009], *s = S, a[3000009];
int c[3000009], f[3000009], l[3000009], r[3000009], t, m, n;
void M(int k, int x) {
  for (f[k] = x, t--; k <= m; k += k & -k) c[k]--;
}
int A(int x) {
  int s = 0, i = 1 << 22;
  for (x--; i; i >>= 1)
    if (s + i <= m && c[s + i] <= x) x -= c[s += i];
  return s + 1;
}
int main() {
  scanf("%s%d%d", S + 1, &m, &n);
  for (int i = 1; i <= n; i++) scanf("%d%d", &l[i], &r[i]);
  for (int i = 0; i <= m; i++) c[i] = i & -i;
  t = m;
  for (int i = n; i; i--)
    for (int j = 1, k = l[i] + 1; j <= r[i] - l[i] + 1 && r[i] <= t;
         M(A(r[i] + 1), A(k)), j++, k += 2)
      if (k > r[i]) k = l[i];
  for (int i = 1; i <= m; i++) putchar(a[i] = (f[i] ? a[f[i]] : *(++s)));
}
