#include <bits/stdc++.h>
using namespace std;
string s;
char ans[3000030];
int x[5050], y[5050], sum[3000030 << 2], fa[3000030];
int n, k;
void build(int k, int l, int r) {
  sum[k] = r - l + 1;
  if (l == r) return;
  int m = l + r >> 1;
  build(k * 2, l, m);
  build(k * 2 + 1, m + 1, r);
}
int update(int t, int k, int l, int r) {
  sum[k]--;
  if (l == r) return l;
  int m = l + r >> 1;
  if (sum[k * 2] >= t)
    return update(t, k * 2, l, m);
  else
    return update(t - sum[k * 2], k * 2 + 1, m + 1, r);
}
int find(int t, int k, int l, int r) {
  if (l == r) return l;
  int m = l + r >> 1;
  if (sum[k * 2] >= t)
    return find(t, k * 2, l, m);
  else
    return find(t - sum[k * 2], k * 2 + 1, m + 1, r);
}
int main() {
  cin >> s;
  s = '$' + s;
  scanf("%d%d", &k, &n);
  for (int i = 1; i <= n; i++) scanf("%d%d", &x[i], &y[i]);
  build(1, 1, k);
  for (int i = n; i; i--)
    if (y[i] < sum[1]) {
      int now = x[i] + 1, len = y[i] - x[i] + 1;
      if (now > y[i]) now = y[i];
      for (int j = 1; j <= len && y[i] < sum[1]; j++) {
        int t = update(y[i] + 1, 1, 1, k);
        fa[t] = find(now, 1, 1, k);
        now += 2;
        if (now > y[i]) now = x[i];
      }
    }
  for (int i = 1, j = 1; i <= k; i++) {
    if (fa[i])
      ans[i] = ans[fa[i]];
    else
      ans[i] = s[j++];
  }
  puts(ans + 1);
  return 0;
}
