#include <bits/stdc++.h>
using namespace std;
inline int getint() {
  int x = 0, f = 1;
  char ch = getchar();
  while (ch < '0' || '9' < ch) {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while ('0' <= ch && ch <= '9') {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  return f * x;
}
int n, m;
int ntot = 0;
int id[85];
int f[100005][85];
int mxr[100005][85];
int fr[100005];
inline void upmx(int &x, int y) { x = max(x, y); }
inline void insert(int x, int y) {
  fr[y] = x;
  upmx(mxr[x][(y - 1) / 1264 + 1], y);
}
int lg[100005], bin[100005];
int ST[100005][20];
inline void STinit() {
  memset(ST, 0, sizeof(ST));
  for (int i = 1; i <= n; i++) ST[i][0] = i;
}
inline void STmdf(int x, int y) {
  ST[x][0] = y;
  int *p = ST[x];
  for (int j = 1; x + bin[j] - 1 <= n; j++)
    p[j] = max(p[j - 1], ST[x + bin[j - 1]][j - 1]);
}
inline int STqry(int l, int r) {
  if (r < l) return 0;
  int t = lg[r - l + 1];
  return max(ST[l][t], ST[r - bin[t] + 1][t]);
}
int main() {
  n = getint(), m = getint();
  lg[0] = -1;
  for (int i = 1; i < 100005; i++) lg[i] = lg[i >> 1] + 1;
  bin[0] = 1;
  for (int i = 1; i < 20; i++) bin[i] = bin[i - 1] << 1;
  for (int i = 1; i <= n; i++) fr[i] = i;
  for (ntot = 1; ntot * 1264 <= n; ntot++) id[ntot] = ntot * 1264;
  ntot--;
  for (int i = 1; i <= m; i++) {
    int x = getint(), y = getint();
    insert(x, y);
  }
  for (int i = 1; i <= n; i++) {
    mxr[i][0] = i;
    for (int j = 1; j <= ntot; j++) upmx(mxr[i][j], mxr[i][j - 1]);
  }
  for (int j = 1; j <= ntot; j++) {
    f[id[j]][j] = id[j];
    STmdf(id[j], id[j]);
    for (int i = id[j] - 1; i >= 1; i--) {
      f[i][j] = max(i, STqry(i + 1, mxr[i][j]));
      STmdf(i, f[i][j]);
    }
  }
  int qq = getint();
  while (qq--) {
    int l = getint(), r = getint();
    int R = r / 1264;
    int ans, st;
    if (r - l <= 1264)
      ans = l, st = ans;
    else
      ans = f[l][R], st = id[R];
    for (int i = st + 1; i <= r; i++)
      ans = (fr[i] <= ans && fr[i] >= l) ? i : ans;
    printf("%d\n", ans);
  }
  return 0;
}
