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

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];
    vector<int> g[N], rg[N];
    void init() {
        for (int i = 0; i < N; i++) {
            g[i].clear(); rg[i].clear();
        }
    }
    void add(int a, int b) {
        g[a].push_back(b);
        rg[b].push_back(a);
    }

/*    int idc, id[N], rid[N], par[N];
    void dfs(int p, int b) {
        if (id[p] != -1) return;
        par[p] = b;
        id[p] = idc; rid[idc] = p; idc++;
        for (int d: g[p]) {
            dfs(d, p);
        }
    }*/

    // unionfind
    int p[N];
    int mv[N];
    void merge(int a, int b) {
        p[a] = b;
    }
    int group(int a) {
        if (p[a] == -1) return a;
        int pa = group(p[a]);
        if (lc.ord[sdom[mv[a]]] > lc.ord[sdom[mv[p[a]]]]) {
            mv[a] = mv[p[a]];
        }
        return p[a] = pa;
    }

    vector<int> bucket[N];
    int V[N];
    struct Edge {
        int to;
    };
    Graph<Edge> gg;
    LowLink lc;
    void exec(int s, int n = N) {
        // uf init
        fill_n(p, n, -1);
        iota(mv, mv+n, 0);

//        fill_n(id, n, -1);
//        idc = 0;

        gg = Graph<Edge>(n);
        for (int i = 0; i < n; i++) {
            for (int d: g[i]) {
                gg[i].push_back(Edge{d});
            }
        }
        lc = LowLink(gg, 0);
//        dfs(s, -1);
//        for (int i = 0; i < n; i++) {
//            printf("%d %d\n", id[i], lc.ord[i]);
//        }
        iota(sdom, sdom+n, 0);

        for (int i = n-1; i > 0; i--) {
            int u = lc.vlis[i];
//            printf("u %d %d\n", rid[i], lc.vlis[i]);
            for (int v: rg[u]) {
                group(v);
                sdom[u] = lc.vlis[min(lc.ord[sdom[u]], lc.ord[sdom[mv[v]]])];
            }
            bucket[sdom[u]].push_back(u);
            for (int v: bucket[lc.par[u]]) {
                group(v);
                V[v] = mv[v];
            }
            bucket[lc.par[u]].clear();
            merge(u, lc.par[u]);
        }

        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;
 
int main() {
    int n, m;
    cin >> n >> m;
    for (int i = 0; i < m; i++) {
        int s, t;
        cin >> s >> t; s--; t--;
        dn.add(s, t);
    }
    dn.exec(0, n);
    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: 29744