#include <cstdio>
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <numeric>
#include <cassert>

using namespace std;
using ll = long long;
constexpr ll TEN(int n) { return (!n) ? 1 : 10 * TEN(n-1); }
 
template <class E>
using Graph = vector<vector<E>>;

struct LowLink {
    vector<int> low, ord, par;
    vector<int> vlis;
    
    LowLink() {}
    template<class E>
    LowLink(const Graph<E> &g, int r) { exec(g, r); }

    template<class E>
    void exec(const Graph<E> &g, int r) {
        int V = (int)g.size();
        low.resize(V); ord.resize(V); par.resize(V);
        co = 0; used.resize(V);
        fill_n(used.begin(), V, false);
        dfs(g, r, -1);
    }
    int co;
    vector<bool> used;
    template<class E>
    void dfs(const Graph<E> &g, int p, int b) {
        used[p] = true;
        bool rt = true;
        low[p] = ord[p] = co++;
        vlis.push_back(p);
        par[p] = b;
        for (E e: g[p]) {
            if (rt and e.to == b) {
                rt = false;
                continue;
            }
            if (!used[e.to]) {
                dfs(g, e.to, p);
                low[p] = min(low[p], low[e.to]);
            } else {
                low[p] = min(low[p], ord[e.to]);
            }
        }
    }
};

template <int N>
struct Dominator {
    int idom[N], sdom[N];

    // unionfind
    int p[N]; // parent
    int mv[N]; // min sdom's v
    int group(int a) {
        if (p[a] == -1) return mv[a];
        group(p[a]);
        if (lc.ord[sdom[mv[a]]] > lc.ord[sdom[mv[p[a]]]]) {
            mv[a] = mv[p[a]];
        }
        p[a] = (p[p[a]] == -1 ? p[a] : p[p[a]]);
        return mv[a];
    }

    vector<int> bucket[N];
    int V[N];
    LowLink lc;
    template<class E>
    void exec(const Graph<E> &g, const Graph<E> &rg, int s) {
        int n = (int)g.size();
        // uf init
        fill_n(p, n, -1);

        lc = LowLink(g, 0);

        iota(mv, mv+n, 0);
        iota(sdom, sdom+n, 0);

        for (int i = n-1; i > 0; i--) {
            int u = lc.vlis[i];
            for (E e: rg[u]) {
                sdom[u] = lc.vlis[min(lc.ord[sdom[u]], lc.ord[sdom[group(e.to)]])];
            }
            bucket[sdom[u]].push_back(u);
            for (int v: bucket[lc.par[u]]) {
                V[v] = group(v);
            }
//            bucket[lc.par[u]].clear(); //koreiru?
            p[u] = lc.par[u]; // uf merge
        }

        idom[s] = -1;
        for (int i = 1; i < n; i++) {
            int u = lc.vlis[i], v = V[u];
            if (sdom[u] == sdom[v]) idom[u] = sdom[u];
            else idom[u] = idom[v];
        }
    }
};
 
const int MN = 100100;
Dominator<MN> dn;
 
struct Edge {
    int to;
} ;
int main() {
    int n, m;
    cin >> n >> m;
    Graph<Edge> g(n), rg(n);
    for (int i = 0; i < m; i++) {
        int s, t;
        cin >> s >> t; s--; t--;
        g[s].push_back(Edge{t});
        rg[t].push_back(Edge{s});
//        dn.add(s, t);
    }
    dn.exec(g, rg, 0);
    int q;
    cin >> q;
    for (int i = 0; i < q; i++) {
        int r;
        cin >> r; r--;
        if (dn.idom[r] != 0) {
            cout << dn.idom[r]+1 << endl;
        } else {
            cout << r+1 << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 24124