685_B. Kay and Snowflake_36772
After the piece of a devilish mirror hit the Kay's eye, he is no longer interested in the beauty of the roses. Now he likes to watch snowflakes.

Once upon a time, he found a huge snowflake that has a form of the tree (connected acyclic graph) consisting of n nodes. The root of tree has index 1. Kay is very interested in the structure of this tree.

After doing some research he formed q queries he is interested in. The i-th query asks to find a centroid of the subtree of the node vi. Your goal is to answer all queries.

Subtree of a node is a part of tree consisting of this node and all it's descendants (direct or not). In other words, subtree of node v is formed by nodes u, such that node v is present on the path from u to root.

Centroid of a tree (or a subtree) is a node, such that if we erase it from the tree, the maximum size of the connected component will be at least two times smaller than the size of the initial tree (or a subtree).

Input

The first line of the input contains two integers n and q (2 ≤ n ≤ 300 000, 1 ≤ q ≤ 300 000) — the size of the initial tree and the number of queries respectively.

The second line contains n - 1 integer p2, p3, ..., pn (1 ≤ pi ≤ n) — the indices of the parents of the nodes from 2 to n. Node 1 is a root of the tree. It's guaranteed that pi define a correct tree.

Each of the following q lines contain a single integer vi (1 ≤ vi ≤ n) — the index of the node, that define the subtree, for which we want to find a centroid.

Output

For each query print the index of a centroid of the corresponding subtree. If there are many suitable nodes, print any of them. It's guaranteed, that each subtree has at least one centroid.

Example

Input

7 4
1 1 3 3 5 3
1
2
3
5


Output

3
2
3
6

Note

<image>

The first query asks for a centroid of the whole tree — this is node 3. If we delete node 3 the tree will split in four components, two of size 1 and two of size 2.

The subtree of the second node consists of this node only, so the answer is 2.

Node 3 is centroid of its own subtree.

The centroids of the subtree of the node 5 are nodes 5 and 6 — both answers are considered correct.
import java.io.*;
import java.util.*;


public class Main {
    private BufferedReader in;
    private StringTokenizer line;
    private PrintWriter out;
    private boolean isDebug;

    public Main(boolean isDebug) {
        this.isDebug = isDebug;
    }

    private static final int mm = 1000000007;

    private long mult(long a, long b) {
        return a * b % mm;
    }

    private ArrayList<Integer>[] g;
    private int[] mx;
    private int[] sz;
    private int[] res;
    private int[] prev;

    public void solve() throws IOException {
//        for (int rr = 0; rr < 100; rr++)
        {
//            out.println(rr);
//            out.flush();
//            Random r = new Random(5);
            int n = nextInt();
            int q = nextInt();
//            int n = 10, q = n;
            g = new ArrayList[n];
            for (int i = 0; i < n; i++) {
                g[i] = new ArrayList<>();
            }
            prev = new int[n];
            prev[0] = -1;
            for (int i = 1; i < n; i++) {
//                int j = r.nextInt(i);
                int j = nextInt() - 1;
                g[j].add(i);
                prev[i] = j;
            }
            sz = new int[n];
            mx = new int[n];
            res = new int[n];
            bb = new int[n];
            qq = new int[n];
            go(0);
            for (int i = 0; i < q; i++) {
//                int num = i + 1;
                int num = nextInt();
                out.println(res[num - 1] + 1);
            }
        }
    }

    private int[] bb;
    private int[] qq;
    private int bbcolor = 13;

    private void go(int v) {
        int s = 1;
        int mxx = 0;
        for (int i : g[v]) {
            go(i);
            s += sz[i];
            mxx = Math.max(mxx, sz[i]);
        }
        sz[v] = s;
        mx[v] = mxx;
        int s2 = s / 2;
        if (mxx <= s2) {
            res[v] = v;
            return;
        }
        int qqe = 0;
        bbcolor++;
        for (int i : g[v]) {
            int ti = res[i];
            if (bb[ti] != bbcolor) {
                bb[ti] = bbcolor;
                qq[qqe++] = ti;
            }
        }
        int qqs = 0;
        while (qqs < qqe) {
            int tv = qq[qqs++];
            if (mx[tv] <= s2 && s - sz[tv] <= s2) {
                res[v] = tv;
                return;
            } else {
                int ti = prev[tv];
                if (ti >= 0 && bb[ti] != bbcolor) {
                    bb[ti] = bbcolor;
                    qq[qqe++] = ti;
                }
            }
        }
    }


    private long pow(long a, int n) {
        if (n == 0) return 1;
        long t = pow(a, n / 2);
        t = mult(t, t);
        if (n % 2 != 0) t = mult(a, t);
        return t;
    }

    public static void main(String[] args) throws IOException {
        new Main(args.length > 0 && "DEBUG_MODE".equals(args[0])).run(args);
    }

    public void run(String[] args) throws IOException {
        if (isDebug) {
            in = new BufferedReader(new InputStreamReader(new FileInputStream("input.txt")));
        } else {
            in = new BufferedReader(new InputStreamReader(System.in));
        }
        out = new PrintWriter(System.out);
//        out = new PrintWriter("output.txt");

//        int t = nextInt();
        int t = 1;
        for (int i = 0; i < t; i++) {
//            out.print("Case #" + (i + 1) + ": ");
            solve();
        }

        in.close();
        out.flush();
        out.close();
    }

    private int[] nextIntArray(int n) throws IOException {
        int[] res = new int[n];
        for (int i = 0; i < n; i++) {
            res[i] = nextInt();
        }
        return res;
    }

    private long[] nextLongArray(int n) throws IOException {
        long[] res = new long[n];
        for (int i = 0; i < n; i++) {
            res[i] = nextInt();
        }
        return res;
    }

    private int nextInt() throws IOException {
        return Integer.parseInt(nextToken());
    }

    private long nextLong() throws IOException {
        return Long.parseLong(nextToken());
    }

    private double nextDouble() throws IOException {
        return Double.parseDouble(nextToken());
    }

    private String nextToken() throws IOException {
        while (line == null || !line.hasMoreTokens()) {
            line = new StringTokenizer(in.readLine());
        }
        return line.nextToken();
    }

    private static class Pll {
        private long key;
        private long value;

        public Pll(long key, long value) {
            this.key = key;
            this.value = value;
        }
    }

    private static class Pii {
        private int key;
        private int value;

        public Pii(int key, int value) {
            this.key = key;
            this.value = value;
        }

        @Override
        public boolean equals(Object o) {
            if (this == o) return true;
            if (o == null || getClass() != o.getClass()) return false;

            Pii pii = (Pii) o;

            if (key != pii.key) return false;
            return value == pii.value;

        }

        @Override
        public int hashCode() {
            int result = key;
            result = 31 * result + value;
            return result;
        }

        @Override
        public String toString() {
            return "Pii{" +
                    "key=" + key +
                    ", value=" + value +
                    '}';
        }
    }

    private static class Pair<K, V> {
        private K key;
        private V value;

        public Pair(K key, V value) {
            this.key = key;
            this.value = value;
        }

        public K getKey() {
            return key;
        }

        public V getValue() {
            return value;
        }

        @Override
        public boolean equals(Object o) {
            if (this == o) return true;
            if (o == null || getClass() != o.getClass()) return false;

            Pair<?, ?> pair = (Pair<?, ?>) o;

            if (key != null ? !key.equals(pair.key) : pair.key != null) return false;
            return !(value != null ? !value.equals(pair.value) : pair.value != null);

        }

        @Override
        public int hashCode() {
            int result = key != null ? key.hashCode() : 0;
            result = 31 * result + (value != null ? value.hashCode() : 0);
            return result;
        }

        @Override
        public String toString() {
            return "Pair{" +
                    "key=" + key +
                    ", value=" + value +
                    '}';
        }
    }
}
7 4
1 1 3 3 5 3
1
2
3
5
 2 2
1
1
2
 7 4
1 1 3 3 5 3
2
2
3
5
 7 4
1 1 3 3 5 3
2
4
3
5
 7 4
1 1 3 3 5 3
2
3
3
5
 7 4
1 1 3 3 5 3
2
4
3
3
 7 4
1 1 3 3 5 6
2
4
3
5
 7 4
1 1 3 3 5 3
2
5
3
3
 7 4
1 1 3 3 5 3
1
2
3
2
 7 4
1 1 3 3 5 3
4
4
3
5
 7 1
1 1 3 3 5 3
2
4
3
3
 7 4
1 1 3 3 5 3
3
5
3
3
 7 4
1 1 3 3 5 3
7
4
3
5
 7 4
1 1 3 3 5 3
3
5
2
3
 7 4
1 1 3 3 5 3
5
5
2
3
 7 4
1 1 3 2 5 3
5
5
2
3
 2 2
1
1
1
 7 4
1 1 3 3 5 3
1
2
3
7
 7 4
1 1 3 3 5 3
4
2
3
5
 7 4
1 1 3 3 5 3
1
4
3
2
 7 4
1 1 3 3 5 3
4
7
3
5
 7 4
1 1 3 3 5 3
4
5
2
3
 7 4
1 1 3 3 5 3
1
4
3
7
 7 4
1 1 3 3 5 3
4
2
2
5
 7 4
1 1 3 4 5 3
2
4
3
3
 7 4
1 2 3 3 5 3
1
2
3
2
 7 4
1 1 3 3 5 3
4
5
3
5
 7 4
1 1 3 4 5 3
7
4
3
5
 7 4
1 1 3 3 5 5
3
5
2
3
 7 4
1 1 3 3 5 3
4
2
3
4
 7 4
1 2 3 3 5 3
1
4
3
2
 7 1
1 1 3 3 5 3
4
7
3
5
 7 4
1 1 3 3 5 3
4
2
2
3
 7 4
1 1 3 3 5 3
2
4
3
7
 7 4
1 1 3 3 5 3
7
2
2
5
 7 4
1 1 3 3 5 3
2
3
5
5
 7 4
1 1 3 3 5 3
2
7
3
3
 7 4
1 1 3 3 5 3
4
4
2
5
 7 4
1 1 6 3 5 3
5
5
2
3
 7 4
1 1 3 3 5 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