#include <bits/stdc++.h>
using namespace std;
int from[100005];
vector<int> t[100005];
vector<pair<int, int> > p[100005];
int n, m, q;
int ans[100005];
int sta[100005];
int calc(int x, int y) {
  int mx = x;
  for (int i = x; i <= y; i++) {
    if (x <= from[i] && from[i] <= mx) mx = i;
  }
  return mx;
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= m; i++) {
    int x, y;
    scanf("%d%d", &x, &y);
    if (x == y) continue;
    t[x].push_back(y);
    from[y] = x;
  }
  int block = 350;
  scanf("%d", &q);
  for (int i = 1; i <= q; i++) {
    int x, y;
    scanf("%d%d", &x, &y);
    if (y - x + 1 <= block) {
      ans[i] = calc(x, y);
      continue;
    }
    p[x].push_back(make_pair(y, i));
  }
  for (int md = block; md <= n; md += block) {
    sta[0] = 0;
    for (int i = md - 1; i >= 1; i--) {
      sta[++sta[0]] = i;
      if (t[i].size())
        for (int j = 0; j <= t[i].size() - 1; j++) {
          int tmp = t[i][j];
          if (tmp > md) continue;
          while (sta[0] && sta[sta[0]] < tmp) sta[0]--;
        }
      if (p[i].size() == 0) continue;
      for (int j = 0; j <= p[i].size() - 1; j++) {
        int wz = p[i][j].first, id = p[i][j].second;
        if (md <= wz && wz < md + block) {
          int now;
          if (sta[0] == 0)
            now = md;
          else
            now = sta[sta[0]];
          for (int k = md; k <= wz; k++) {
            if (i <= from[k] && from[k] <= now) now = k;
          }
          ans[id] = now;
        }
      }
    }
  }
  for (int i = 1; i <= q; i++) printf("%d\n", ans[i]);
  return 0;
}
