Problem: Petya has a simple graph (that is, a graph without loops or multiple edges) consisting of n vertices and m edges.

The weight of the i-th vertex is a_i.

The weight of the i-th edge is w_i.

A subgraph of a graph is some set of the graph vertices and some set of the graph edges. The set of edges must meet the condition: both ends of each edge from the set must belong to the chosen set of vertices. 

The weight of a subgraph is the sum of the weights of its edges, minus the sum of the weights of its vertices. You need to find the maximum weight of subgraph of given graph. The given graph does not contain loops and multiple edges.

Input

The first line contains two numbers n and m (1 ≤ n ≤ 10^3, 0 ≤ m ≤ 10^3) - the number of vertices and edges in the graph, respectively.

The next line contains n integers a_1, a_2, ..., a_n (1 ≤ a_i ≤ 10^9) - the weights of the vertices of the graph.

The following m lines contain edges: the i-e edge is defined by a triple of integers v_i, u_i, w_i (1 ≤ v_i, u_i ≤ n, 1 ≤ w_i ≤ 10^9, v_i ≠ u_i). This triple means that between the vertices v_i and u_i there is an edge of weight w_i. It is guaranteed that the graph does not contain loops and multiple edges.

Output

Print one integer — the maximum weight of the subgraph of the given graph.

Examples

Input


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


Output


8


Input


3 3
9 7 8
1 2 1
2 3 2
1 3 3


Output


0

Note

In the first test example, the optimal subgraph consists of the vertices {1, 3, 4} and has weight 4 + 4 + 5 - (1 + 2 + 2) = 8. In the second test case, the optimal subgraph is empty.

Solution (in JAVA):

Solution:
import java.lang.*;
import java.math.*;
import java.util.*;
import java.io.*;

public class Main {
    void solve() {
        int n=ni(),m=ni();
        MaximumFlowGraph g=new MaximumFlowGraph(n+m+2,0,n+m+1);
        for(int i=1;i<=n;i++){
            int w=ni();
            g.addEdge(i,n+m+1,w);
        }
        long ans=0;
        for(int i=1;i<=m;i++){
            int u=ni(),v=ni(),w=ni();
            g.addEdge(n+i,u,g.INF);
            g.addEdge(n+i,v,g.INF);
            g.addEdge(0,n+i,w);
            ans+=w;
        }
        ans-=g.getFlow(0,n+m+1);
        pw.println(ans);
    }
    static class MaximumFlowGraph {

        final long INF = (long) 1e15;

        public class Edge {
            public int from;
            public int to;
            public long flow;
            public long cap;

            Edge(int from, int to, long cap) {
                this.from = from;
                this.to = to;
                this.cap = cap;
                this.flow = 0;
            }

            boolean isOpen(){
                return cap > flow;
            }

            long getLeft(){
                return cap - flow;
            }
        }

        public ArrayList<Edge> e = new ArrayList<>();
        long[] dist;
        int[] parEdge;
        int[] first;
        ArrayList<Integer>[] g;
        int source;
        int sink;

        public void setzeroflow(){
            for (int i = 0; i < e.size(); i++) {
                Edge ee = e.get(i);
                ee.flow = 0;
            }
        }

        public MaximumFlowGraph(int size, int source, int sink) {
            this.source = source;
            this.sink = sink;
            dist = new long[size];
            parEdge = new int[size];
            first = new int[size];
            g = new ArrayList[size];
            for (int i = 0; i < size; i++)
                g[i] = new ArrayList<>();
        }

        public void addEdge(int from, int to, long cap){
            int size = e.size();
            e.add(new Edge(from, to, cap));
            e.add(new Edge(to, from, 0));
            g[from].add(size);
            g[to].add(size + 1);
        }

        private boolean bfs(){
            Arrays.fill(dist, INF);
            dist[source] = 0;
            Queue<Integer> q = new ArrayDeque<>();
            q.add(source);
            while (!q.isEmpty()) {
                int v = q.poll();
                for (int j : g[v]) {
                    Edge curr = e.get(j);
                    int to = curr.to;

                    if (curr.isOpen() && dist[to] > dist[v] + 1) {
                        dist[to] = dist[v] + 1;
                        q.add(to);
                        if (to == sink)
                            return true;

                    }

                }
            }
            return dist[sink] != INF;
        }

        private boolean dfs(int v, int pe){
            parEdge[v] = pe;
            if (v == sink)
                return true;
            if (dist[v] >= dist[sink])
                return false;
            for (; first[v] < g[v].size(); first[v]++) {
                Edge curr = e.get(g[v].get(first[v]));
                if (curr.isOpen() && dist[curr.to] == dist[v] + 1 && dfs(curr.to, g[v].get(first[v])))
                    return true;
            }
            return false;
        }

        long pushFlow(){
            long add = INF;
            int v = sink;
            while (v != source) {
                Edge curr = e.get(parEdge[v]);
                add = Math.min(add, curr.getLeft());
                v = curr.from;
            }
            v = sink;
            while (v != source) {
                int i = parEdge[v];
                e.get(i).flow += add;
                e.get(i ^ 1).flow -= add;
                v = e.get(i).from;
            }
            return add;
        }

        public long getFlow(int source, int sink){

            this.source = source;
            this.sink = sink;

            long flow = 0;
            while (bfs()) {
                Arrays.fill(first, 0);
                while (dfs(source, -1))
                    flow += pushFlow();
            }
            return flow;
        }

    }


    long M = (long)1e9+7;
    InputStream is;
    PrintWriter pw;
    String INPUT = "";

    void run() throws Exception {
        is = INPUT.isEmpty() ? System.in : new ByteArrayInputStream(INPUT.getBytes());
        pw = new PrintWriter(System.out);
        long s = System.currentTimeMillis();
        solve();
        pw.flush();
        if (!INPUT.isEmpty()) tr(System.currentTimeMillis() - s + "ms");

    }

    public static void main(String[] args) throws Exception {
        new Main().run();
    }

    private byte[] inbuf = new byte[1024];
    public int lenbuf = 0, ptrbuf = 0;

    private int readByte() {
        if (lenbuf == -1) throw new InputMismatchException();
        if (ptrbuf >= lenbuf) {
            ptrbuf = 0;
            try {
                lenbuf = is.read(inbuf);
            } catch (IOException e) {
                throw new InputMismatchException();
            }
            if (lenbuf <= 0) return -1;
        }
        return inbuf[ptrbuf++];
    }

    private boolean isSpaceChar(int c) {
        return !(c >= 33 && c <= 126);
    }

    private int skip() {
        int b;
        while ((b = readByte()) != -1 && isSpaceChar(b)) ;
        return b;
    }

    private double nd() {
        return Double.parseDouble(ns());
    }

    private char nc() {
        return (char) skip();
    }

    private String ns() {
        int b = skip();
        StringBuilder sb = new StringBuilder();
        while (!(isSpaceChar(b))) { // when nextLine, (isSpaceChar(b) && b != ' ')
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }

    private char[] ns(int n) {
        char[] buf = new char[n];
        int b = skip(), p = 0;
        while (p < n && !(isSpaceChar(b))) {
            buf[p++] = (char) b;
            b = readByte();
        }
        return n == p ? buf : Arrays.copyOf(buf, p);
    }

    private char[][] nm(int n, int m) {
        char[][] map = new char[n][];
        for (int i = 0; i < n; i++) map[i] = ns(m);
        return map;
    }

    private int[] na(int n) {
        int[] a = new int[n];
        for (int i = 0; i < n; i++) a[i] = ni();
        return a;
    }

    private int ni() {
        int num = 0, b;
        boolean minus = false;
        while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-')) ;
        if (b == '-') {
            minus = true;
            b = readByte();
        }

        while (true) {
            if (b >= '0' && b <= '9') {
                num = num * 10 + (b - '0');
            } else {
                return minus ? -num : num;
            }
            b = readByte();
        }
    }

    private long nl() {
        long num = 0;
        int b;
        boolean minus = false;
        while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-')) ;
        if (b == '-') {
            minus = true;
            b = readByte();
        }

        while (true) {
            if (b >= '0' && b <= '9') {
                num = num * 10 + (b - '0');
            } else {
                return minus ? -num : num;
            }
            b = readByte();
        }
    }

    private boolean oj = System.getProperty("ONLINE_JUDGE") != null;

    private void tr(Object... o) {
        if (INPUT.length() > 0) System.out.println(Arrays.deepToString(o));
    }

}