#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }
const int MAXN = 100000;
const int SZ = 400;
const int MAXB = (MAXN + SZ - 1) / SZ;
int n, m, nq;
int nb;
int jump[MAXN][MAXB];
int radj[MAXN];
vector<int> adj[MAXN];
int idx[MAXN];
int stck[MAXN], nstck;
int calc(int l, int r, int at, int done) {
  for (int to = (done + 1); to <= (r); ++to)
    if (radj[to] != -1 && l <= radj[to] && radj[to] <= at) at = to;
  return at;
}
void run() {
  scanf("%d%d", &n, &m);
  for (int i = (0); i < (n); ++i) adj[i].clear(), radj[i] = -1;
  for (int i = (0); i < (m); ++i) {
    int a, b;
    scanf("%d%d", &a, &b);
    --a, --b;
    adj[a].push_back(b);
    radj[b] = a;
  }
  for (int i = (0); i < (n); ++i) sort(adj[i].begin(), adj[i].end());
  nb = (n + SZ - 1) / SZ;
  for (int i = (0); i < (n); ++i) idx[i] = 0;
  for (int j = (0); j < (nb); ++j) {
    nstck = 0;
    for (int at = min(n - 1, j * SZ); at >= 0; --at) {
      int to = at;
      while (idx[at] + 1 < ((int)(adj[at]).size()) &&
             adj[at][idx[at] + 1] <= j * SZ)
        ++idx[at];
      if (idx[at] < ((int)(adj[at]).size()) && adj[at][idx[at]] <= j * SZ)
        to = adj[at][idx[at]];
      int best = to;
      while (nstck > 0 && to >= stck[nstck - 1]) best = jump[stck[--nstck]][j];
      jump[at][j] = best;
      stck[nstck++] = at;
    }
  }
  scanf("%d", &nq);
  for (int qi = (0); qi < (nq); ++qi) {
    int l, r;
    scanf("%d%d", &l, &r);
    --l, --r;
    int j = r / SZ;
    int ret = l <= j * SZ ? calc(l, r, jump[l][j], j * SZ) : calc(l, r, l, l);
    printf("%d\n", ret + 1);
  }
}
int main() {
  run();
  return 0;
}
