This page is still under construction.

Parts of this page are still being built. What you see may change.

Worms

Time limit1sMemory limit128 MB

Summary
On a tree, worms each move every hour to an adjacent house; decide whether they can all meet and find the minimum number of hours.
Level

Hard8 of 10

Topics
Tree, Graph, Math, Binary search
Solved
No attempts yet

Problem

In the mysterious Land of Worms there are many worm-houses. Not all of them are inhabited, and each house holds at most one worm. Some pairs of houses are joined by a path. For every pair of distinct houses there is exactly one route made of paths on which no path is used twice, so the houses and paths together form a tree.

One day all of the worms decide to gather in a single house. They agree that, at the start of every hour, each worm walks along one path out of the house it is currently in and reaches the house at the other end of that path (walking along any path takes exactly one hour). A worm must move every hour and can never stay in place. The worms keep moving until the moment when every one of them is in the same house at the same time.

Meeting this way can take a long time, and sometimes it is impossible. Help the worms find out whether a meeting can be arranged and, if it can, how many hours it takes in the best case.

Write a program that:

  • reads the description of the Land of Worms from standard input,
  • decides whether the worms can meet and, if so, the least number of hours it takes,
  • writes the answer to standard output.

Input

The first line contains two integers nn and mm (2≤n≤500002 \le n \le 50000, 1≤m≤500001 \le m \le 50000), separated by a single space, denoting the number of houses and the number of paths. Houses are numbered from 11 to nn.

Each of the next mm lines contains two integers aa and bb (1≤a,b≤n1 \le a, b \le n), separated by a single space, describing a path that connects houses aa and bb.

The next line contains one integer kk (2≤k≤n2 \le k \le n), the number of worms. Each of the following kk lines contains one integer dd (1≤d≤n1 \le d \le n), the house in which one worm lives. No two worms live in the same house.

Output

Print a single line. If the worms can never all meet under these rules, print the word NIE (Polish for no). Otherwise print one integer: the least number of hours needed for all worms to gather in one house.

Hint

Examples1

  1. Example 1

    Input
    6 5
    1 2
    2 3
    2 4
    4 5
    4 6
    3
    2
    5
    6
    
    Expected output
    1