# Maximum flow and matchings

# Maximum Flow B

The bipartite graph, source and sink are given. Each disjoint set consists of **n** vertices. The edges with capacities `a`

run from the source to the vertices of the left set, from each vertex of the right set the edges of capacity _{i}`b`

run to the sink. The edges also run from the vertices of the left set to the vertices of the right set of infinite capacity. The current can flow in both directions along these edges. Find the value of maximum flow from source to the sink._{i}

#### Input

The numbers **n** and **k** (**1** ≤ **n** ≤ `10`

, ^{4}**0** ≤ **k** ≤ `10`

) are given - the number of vertices in each part of the graph and the number of edges between them. The second line contains the numbers ^{5}`a`

(_{i}**1** ≤ `a`

≤ _{i}`10`

) - the edge capacities from source to each vertex in the left set. The third line contains the numbers ^{4}`b`

(_{i}**1** ≤ `b`

≤ _{i}`10`

) - the edge capacities from each vertex of the right set to the sink. In each of the next ^{4}**k** lines two numbers **u** and **v** (**1** ≤ **u**, **v** ≤ **n**) are given - the edge connects the vertex **u** of the left set and the vertex **v** of the right set.

#### Output

Print the value of maximum flow.

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

6