#include <bits/stdc++.h>
using namespace std;
namespace IOstream_chhokmah {
long long read() {
  long long x = 0, w = 0;
  char ch = 0;
  while (ch < '0' || ch > '9') {
    if (ch == '-') w = 1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9')
    x = (x << 1) + (x << 3) + (ch ^ 48), ch = getchar();
  return w ? -x : x;
}
template <typename T>
void write(T x) {
  if (x < 0) putchar('-'), x = -x;
  if (x > 9) write(x / 10);
  putchar(x % 10 + '0');
}
template <typename T>
void write(T x, char ch) {
  write(x);
  putchar(ch);
}
template <typename T>
void writeln(T x) {
  write(x);
  puts("");
}
}  // namespace IOstream_chhokmah
using namespace IOstream_chhokmah;
namespace chhokmah {
const int N = 3e6 + 5;
struct Query {
  int l, r;
} q[N];
char s[N], ans[N];
int k, n;
int pre[N], tr[N];
void add(int pos, int val) {
  for (int i = pos; i <= k; i += (i & -i)) tr[i] += val;
}
int query(int x) {
  int l = log2(k), sum = 0, ans = 0;
  for (int i = l; i >= 0; i--) {
    int kk = (1 << i);
    if (ans + kk <= k && sum + tr[ans + kk] < x) sum += tr[ans + kk], ans += kk;
  }
  return ans + 1;
}
int main() {
  scanf("%s", s + 1);
  k = read(), n = read();
  for (int i = 1; i <= k; i++) tr[i] = (i & -i);
  for (int i = 1; i <= n; i++) q[i].l = read(), q[i].r = read();
  for (int now = k, i = n; i >= 1; i--) {
    for (int x = q[i].l + 1, j = 1; q[i].r < now && j <= q[i].r - q[i].l + 1;
         x += 2, j++, now--) {
      if (x > q[i].r) x = q[i].l;
      int tmp = query(q[i].r + 1);
      add(tmp, -1);
      pre[tmp] = query(x);
    }
  }
  for (int i = 1, j = 0; i <= k; i++) ans[i] = pre[i] ? ans[pre[i]] : s[++j];
  puts(ans + 1);
  return 0;
}
}  // namespace chhokmah
int main() { return chhokmah::main(); }
