Problem: You are given an undirected graph consisting of vertices. A number is written on each vertex; the number on vertex is . Initially there are no edges in the graph.
You may add some edges to this graph, but you have to pay for them. The cost of adding an edge between vertices and is coins. There are also special offers, each of them is denoted by three numbers , and , and means that you can add an edge connecting vertices and and pay coins for it. You don't have to use special offers: if there is a pair of vertices and that has a special offer associated with it, you still may connect these two vertices paying coins for it.
What is the minimum number of coins you have to spend to make the graph connected? Recall that a graph is connected if it's possible to get from any vertex to any other vertex using only the edges belonging to this graph.
Input Format: The first line contains two integers and (, ) — the number of vertices in the graph and the number of special offers, respectively.
The second line contains integers () — the numbers written on the vertices.
Then lines follow, each containing three integers , and (, , ) denoting a special offer: you may add an edge connecting vertex and vertex , and this edge will cost coins.
Output Format: Print one integer — the minimum number of coins you have to pay to make the graph connected.
Note: In the first example it is possible to connect to using special offer , and then to without using any offers.
In next two examples the optimal answer may be achieved without using special offers.