{"raw_statement":[{"iden":"problem statement","content":"There are $N$ kinds of magical gems, numbered $1, 2, \\ldots, N$, distributed in the AtCoder Kingdom.  \nTakahashi is trying to make an ornament by arranging gems in a row.  \nFor some pairs of gems, we can put the two gems next to each other; for other pairs, we cannot. We have $M$ pairs for which the two gems can be adjacent: (Gem $A_1$, Gem $B_1$), (Gem $A_2$, Gem $B_2$), $\\ldots$, (Gem $A_M$, Gem $B_M$). For the other pairs, the two gems cannot be adjacent. (Order does not matter in these pairs.)  \nDetermine whether it is possible to form a sequence of gems that has one or more gems of each of the kinds $C_1, C_2, \\dots, C_K$. If the answer is yes, find the minimum number of stones needed to form such a sequence."},{"iden":"constraints","content":"*   All values in input are integers.\n*   $1 ≤ N ≤ 10^5$\n*   $0 ≤ M ≤ 10^5$\n*   $1 ≤ A_i < B_i ≤ N$\n*   If $i ≠ j$, $(A_i, B_i) ≠ (A_j, B_j)$.\n*   $1 ≤ K ≤ 17$\n*   $1 ≤ C_1 < C_2 < \\dots < C_K ≤ N$"},{"iden":"input","content":"Input is given from Standard Input in the following format:\n\n$N$ $M$\n$A_1$ $B_1$\n$A_2$ $B_2$\n$\\hspace{7mm}\\vdots$\n$A_M$ $B_M$\n$K$\n$C_1$ $C_2$ $\\cdots$ $C_K$"},{"iden":"sample input 1","content":"4 3\n1 4\n2 4\n3 4\n3\n1 2 3"},{"iden":"sample output 1","content":"5\n\nFor example, by arranging the gems in the order $[1, 4, 2, 4, 3]$, we can form a sequence of length $5$ with Gems $1, 2, 3$."},{"iden":"sample input 2","content":"4 3\n1 4\n2 4\n1 2\n3\n1 2 3"},{"iden":"sample output 2","content":"\\-1"},{"iden":"sample input 3","content":"10 10\n3 9\n3 8\n8 10\n2 10\n5 8\n6 8\n5 7\n6 7\n1 6\n2 4\n4\n1 2 7 9"},{"iden":"sample output 3","content":"11\n\nFor example, by arranging the gems in the order $[1, 6, 7, 5, 8, 3, 9, 3, 8, 10, 2]$, we can form a sequence of length $11$ with Gems $1, 2, 7, 9$."}],"translated_statement":null,"sample_group":[],"show_order":["render_html"],"formal_statement":null,"simple_statement":null,"has_page_source":true}