Under construction

Still being built. Things may change

Family Reunion

Interview

Time limit1sMemory limit1024 MB

Summary
Given a family tree as a parent array, find the closest common ancestor of M seated people, which may be one of them.
Level

Easy3 of 10

Topics
Tree, Implementation
Solved
No attempts yet

Problem

A family reunion is held for the descendants of Ida-Ottilia Isaksson. For simplicity, a family tree has been drawn up. All descendants are numbered from 11 to NN, and Ida-Ottilia herself is given the number 00.

Among the MM people at your table, a discussion starts about who their nearest common relative is (closest going up the tree). Write a program that computes this. Note that this sometimes can be someone sitting at the table.

Input

The first line contains the numbers NN and MM (2≤M≤N≤202 \le M \le N \le 20). The second line contains NN numbers, the parent of each descendant (all between 00 and NN). The third line contains MM numbers, the people around the table (all between 11 and NN, with no duplicates).

Output

Print a single number: the number of the nearest common relative of the people at the table.

Examples2

  1. Example 1

    Input
    8 3
    6 0 0 2 0 5 6 5
    1 5 8
    
    Expected output
    5
    
  2. Example 2

    Input
    4 2
    2 0 0 3
    4 1
    
    Expected output
    0