Coloured Leaves

No attempts yetTime limit1sMemory limit128 MB

Problem

You are given a tree TT. Choose one internal vertex (a vertex that is not a leaf) to be the root.

Some vertices may be labelled either "black" or "white" — leaves and the root may be labelled as well. For every leaf ww, the simple path from the root to ww must contain at least one labelled vertex, and the colour of ww is defined by the label of the last labelled vertex on that path (the labelled vertex closest to ww).

You are given an unrooted tree (no root is fixed) whose leaves are already coloured. You may choose any internal vertex of the tree as its root. Find the minimum number of labels needed to reproduce the given leaf colours in the manner described above.

Input

The first line contains two integers mm and nn (2n<m100002 \le n < m \le 10000), where mm is the number of vertices of TT and nn is the number of leaves. The vertices are numbered 1,2,,m1, 2, \dots, m, and the numbers 1,2,,n1, 2, \dots, n are assigned to the leaves.

Each of the next nn lines contains a single number, 00 or 11, describing the colour of a leaf (00 for black, 11 for white). The ii-th of these lines describes the colour of leaf ii.

Each of the following m1m-1 lines contains two integers aa and bb (1a<bm1 \le a < b \le m) separated by a single space, describing one edge of TT.

Output

Print a single integer — the minimum number of labels needed to define the colours of the leaves in the way described in the input.