#include <bits/stdc++.h>
using namespace std;
const int N = 3e6 + 10;
char s[N], ans[N];
int n, k, len, f[N], c[N];
struct opt {
  int l, r;
} a[5050];
inline int lowbit(int x) { return x & -x; }
inline void add(int x, int val) {
  for (; x <= k; x += lowbit(x)) c[x] += val;
}
inline int query(int x) {
  int l = log2(k), sum = 0, ans = 0;
  for (int i = l; i >= 0; i--) {
    int K = (1 << i);
    if (ans + K <= k && sum + c[ans + K] < x) sum += c[ans + K], ans += K;
  }
  return ans + 1;
}
int main() {
  scanf("%s", s + 1);
  scanf("%d%d", &k, &n);
  for (int i = 1; i <= k; i++) c[i] = i & -i;
  for (int i = 1; i <= n; i++) scanf("%d%d", &a[i].l, &a[i].r);
  for (int now = k, i = n; i; i--)
    for (int x = a[i].l + 1, j = 1; a[i].r < now && j <= a[i].r - a[i].l + 1;
         x += 2, j++, now--) {
      if (x > a[i].r) x = a[i].l;
      int tmp = query(a[i].r + 1);
      add(tmp, -1), f[tmp] = query(x);
    }
  for (int i = 1, j = 0; i <= k; i++) ans[i] = f[i] ? ans[f[i]] : s[++j];
  puts(ans + 1);
  return 0;
}
