#include <bits/stdc++.h>
using namespace std;
int n, m;
vector<int> v[100005];
int cur[100005], back[100005], f[100005][320];
inline bool cmp(int a, int b) { return a > b; }
int main() {
  int lp, rp, q, i, j;
  scanf("%d%d", &n, &m);
  for (i = 1; i <= m; i++) {
    scanf("%d%d", &lp, &rp);
    v[lp].push_back(rp);
    back[rp] = lp;
  }
  for (i = 1; i <= n; i++) {
    sort(v[i].begin(), v[i].end(), cmp);
  }
  for (i = 320; i <= n; i += 320) {
    int id = i / 320;
    for (j = 1; j <= n; j++) {
      while (!v[j].empty() && v[j].back() <= i) {
        cur[j] = v[j].back();
        v[j].pop_back();
      }
    }
    f[i][id] = i;
    stack<int> s;
    s.push(i);
    for (j = i - 1; j >= 1; j--) {
      f[j][id] = j;
      while (!s.empty() && s.top() <= cur[j]) {
        f[j][id] = max(f[j][id], f[s.top()][id]);
        s.pop();
      }
      s.push(j);
    }
  }
  scanf("%d", &q);
  for (i = 1; i <= q; i++) {
    scanf("%d%d", &lp, &rp);
    int x = max(lp, f[lp][(rp - 1) / 320]);
    for (j = max(lp, (rp - 1) / 320 * 320); j <= rp; j++) {
      if (back[j] >= lp && back[j] <= x) {
        x = j;
      }
    }
    printf("%d\n", x);
  }
  return 0;
}
