#include <bits/stdc++.h>
using namespace std;
template <class T>
bool umin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
bool umax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
int to[100009], p[100009], n, bel[100009], st[100009], en[100009], ans[100009];
int BLOK;
pair<int, int> arr[100009], d[100009], S[100009];
bool cmp(int x, int y) { return (arr[x].second < arr[y].second); }
void upd(int p, int v) {
  umax(d[p], make_pair(v, p));
  umax(S[bel[p]], d[p]);
}
pair<int, int> get(int l, int r) {
  pair<int, int> res = make_pair(0, 0);
  if (bel[l] == bel[r]) {
    for (int i = l; i <= r; i++) umax(res, d[i]);
    return res;
  }
  for (int i = l; i <= en[bel[l]]; i++) umax(res, d[i]);
  for (int i = st[bel[r]]; i <= r; i++) umax(res, d[i]);
  for (int i = bel[l] + 1; i < bel[r]; i++) umax(res, S[i]);
  return res;
}
int jump(int x) {
  if (d[x].first == x) return x;
  pair<int, int> res = get(x, d[x].first);
  if (res.first <= d[x].first) return d[x].first;
  return jump(res.second);
}
void build() {
  int now = 1;
  for (int i = 1; i <= n; i++) {
    bel[i] = now;
    d[i] = make_pair(i, i);
    umax(S[now], d[i]);
    if (i % BLOK == 0) {
      en[now] = i;
      if (i < n) st[++now] = i + 1;
    }
  }
  if (n % BLOK != 0) en[now] = n;
}
int main() {
  int m;
  scanf("%d%d", &n, &m);
  BLOK = sqrt(n);
  build();
  for (int i = 1; i <= m; i++) {
    int l, r;
    scanf("%d%d", &l, &r);
    if (l != r) to[r] = l;
  }
  int q, pnt = 1;
  scanf("%d", &q);
  for (int i = 1; i <= q; i++) {
    int x, y;
    scanf("%d%d", &x, &y);
    arr[i] = make_pair(x, y);
    p[i] = i;
  }
  sort(p + 1, p + q + 1, cmp);
  for (int i = 1; i <= n; i++) {
    if (to[i]) upd(to[i], i);
    while (pnt <= q and arr[p[pnt]].second == i)
      ans[p[pnt]] = jump(arr[p[pnt]].first), pnt++;
  }
  for (int i = 1; i <= q; i++) printf("%d\n", ans[i]);
  return 0;
}
