#include <bits/stdc++.h>
using namespace std;
int n, m;
int x[100005];
vector<int> g[100005];
int c[100005];
int w[318][100001];
int main() {
  scanf("%d%d", &n, &m);
  memset(x, -1, sizeof(x));
  for (int i = 0; i < (m); i++) {
    int a, b;
    scanf("%d%d", &a, &b);
    a--;
    b--;
    g[a].push_back(b);
    x[b] = a;
  }
  for (int i = 0; i < (n); i++) sort(g[i].begin(), g[i].end());
  for (int k = 0; k * 317 < n; ++k) {
    w[k][k * 317] = k * 317;
    stack<pair<int, int> > st;
    st.push(make_pair(k * 317, k * 317));
    for (int i = k * 317 - 1; i >= 0; --i) {
      while (c[i] < g[i].size() && g[i][c[i]] <= k * 317) c[i]++;
      if (c[i]) {
        c[i]--;
        int j = g[i][c[i]];
        assert(j <= k * 317);
        while (!st.empty() && st.top().first <= j)
          j = max(j, st.top().second), st.pop();
        w[k][i] = j;
        st.push(make_pair(i, j));
      } else
        w[k][i] = i;
    }
  }
  int q;
  scanf("%d", &q);
  while (q--) {
    int a, b;
    scanf("%d%d", &a, &b);
    a--;
    b--;
    int j = b / 317 * 317, r, i;
    if (j >= a)
      i = j, r = w[b / 317][a];
    else
      i = r = a;
    while (i < b) {
      i++;
      if (x[i] >= a && x[i] <= r) r = i;
    }
    printf("%d\n", r + 1);
  }
  return 0;
}
