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.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.Reader;
import java.util.*;
public class PetyaGraph {
    public static void main(String[] args) {
        FastScanner scanner = new FastScanner();
        int N = scanner.nextInt();
        int M = scanner.nextInt();
        int[] vert = new int[N];
        MinCostMaxFlowSolver solver = new EdmondsKarp();
        Node src = solver.addNode();
        Node snk = solver.addNode();
        Node[] vertices = new Node[N];
        for(int i = 0; i < N; i++) {
            vert[i] = scanner.nextInt();
            vertices[i] = solver.addNode();
            solver.link(vertices[i], snk, vert[i], 0);
        }
        long sum = 0;
        for(int i = 0; i < M; i++) {
            int u = scanner.nextInt()-1;
            int v = scanner.nextInt()-1;
            long w = scanner.nextInt();
            sum+=w;
            Node temp = solver.addNode();
            solver.link(temp, vertices[u], Long.MAX_VALUE, 0);
            solver.link(temp, vertices[v], Long.MAX_VALUE, 0);
            solver.link(src, temp, w, 0);
        }
        long[] res = solver.getMinCostMaxFlow(src, snk);
        System.out.println(sum - res[0]);
    }
    public static class Node {
        private Node() {
        }
        List<Edge> edges = new ArrayList<Edge>();
        int index;          // index in nodes array
        int dist;           // Dinic, HIPR and AhujaOrlin.
    }
    public static class Edge {
        boolean forward; // true: edge is in original graph
        Node from, to;   // nodes connected
        long flow;        // current flow
        final long capacity;
        Edge dual;      // reference to this edge's dual
        long cost;      // only used for MinCost.
        protected Edge(Node s, Node d, long c, boolean f) {
            forward = f;
            from = s;
            to = d;
            capacity = c;
        }
        long remaining() {
            return capacity - flow;
        }
        void addFlow(long amount) {
            flow += amount;
            dual.flow -= amount;
        }
    }

    public static abstract class MaxFlowSolver {
        List<Node> nodes = new ArrayList<Node>();
        public void link(Node n1, Node n2, long capacity) {
            link(n1, n2, capacity, 1);
        }
        public void link(Node n1, Node n2, long capacity, long cost) {
            Edge e12 = new Edge(n1, n2, capacity, true);
            Edge e21 = new Edge(n2, n1, 0, false);
            e12.dual = e21;
            e21.dual = e12;
            n1.edges.add(e12);
            n2.edges.add(e21);
            e12.cost = cost;
            e21.cost = -cost;
        }
        void link(int n1, int n2, long capacity) {
            link(nodes.get(n1), nodes.get(n2), capacity);
        }
        protected MaxFlowSolver(int n) {
            for (int i = 0; i < n; i++)
                addNode();
        }
        protected MaxFlowSolver() {
            this(0);
        }
        public abstract long getMaxFlow(Node src, Node snk);
        public Node addNode() {
            Node n = new Node();
            n.index = nodes.size();
            nodes.add(n);
            return n;
        }
        List<Edge> getMinCut(Node src) {
            Queue<Node> bfs = new ArrayDeque<Node>();
            Set<Node> visited = new HashSet<Node>();
            bfs.offer(src);
            visited.add(src);
            while (!bfs.isEmpty()) {
                Node u = bfs.poll();
                for (Edge e : u.edges) {
                    if (e.remaining() > 0 && !visited.contains(e.to)) {
                        visited.add(e.to);
                        bfs.offer(e.to);
                    }
                }
            }
            List<Edge> minCut = new ArrayList<Edge>();
            for (Node s : visited) {
                for (Edge e : s.edges)
                    if (e.forward && !visited.contains(e.to))
                        minCut.add(e);
            }
            return minCut;
        }
        void computeDistanceLabelsByReverseBFS(Node snk, int[] count) {
            final int n = nodes.size();
            count[0]++;
            Node[] Q = new Node[n];  // (Q, head, tail) are used as BFS queue
            int head = 0, tail = 0;
            snk.dist = 0;
            Q[tail++] = snk;
            while (head < tail) {
                Node x = Q[head++];
                for (Edge e : x.edges) {
                    if (e.to.dist == -1) {  // not yet explored
                        e.to.dist = e.from.dist + 1;
                        count[e.to.dist]++;
                        Q[tail++] = e.to;
                    }
                }
            }
        }
    }
    static abstract class MinCostMaxFlowSolver extends MaxFlowSolver {
        abstract long[] getMinCostMaxFlow(Node src, Node snk);
        MinCostMaxFlowSolver() {
            this(0);
        }
        MinCostMaxFlowSolver(int n) {
            super(n);
        }
    }
    static class EdmondsKarp extends MinCostMaxFlowSolver {
        EdmondsKarp() {
            this(0);
        }
        EdmondsKarp(int n) {
            super(n);
        }
        long minCost;
        @Override
        public long[] getMinCostMaxFlow(Node src, Node snk) {
            long maxflow = getMaxFlow(src, snk);
            return new long[]{maxflow, minCost};
        }
        static final long INF = Long.MAX_VALUE / 4;
        @Override
        public long getMaxFlow(Node src, Node snk) {
            final int n = nodes.size();
            final int source = src.index;
            final int sink = snk.index;
            long flow = 0;
            long cost = 0;
            long[] potential = new long[n]; // allows Dijkstra to work with negative edge weights
            while (true) {
                Edge[] parent = new Edge[n]; // used to store an augmenting path
                long[] dist = new long[n]; // minimal cost to vertex
                Arrays.fill(dist, INF);
                dist[source] = 0;
                PriorityQueue<Item> que = new PriorityQueue<Item>();
                que.add(new Item(0, source));
                while (!que.isEmpty()) {
                    Item item = que.poll();
                    if (item.dist != dist[item.v])
                        continue;
                    for (Edge e : nodes.get(item.v).edges) {
                        long temp = dist[item.v] + e.cost + potential[item.v] - potential[e.to.index];
                        if (e.capacity > e.flow && dist[e.to.index] > temp) {
                            dist[e.to.index] = temp;
                            parent[e.to.index] = e;
                            que.add(new Item(temp, e.to.index));
                        }
                    }
                }
                if (parent[sink] == null)
                    break;
                for (int i = 0; i < n; i++)
                    if (parent[i] != null)
                        potential[i] += dist[i];
                long augFlow = Long.MAX_VALUE;
                for (int i = sink; i != source; i = parent[i].from.index)
                    augFlow = Math.min(augFlow, parent[i].capacity - parent[i].flow);
                for (int i = sink; i != source; i = parent[i].from.index) {
                    Edge e = parent[i];
                    e.addFlow(augFlow);
                    cost += augFlow * e.cost;
                }
                flow += augFlow;
            }
            minCost = cost;
            return flow;
        }
        static class Item implements Comparable<Item> {
            long dist;
            int v;
            public Item(long dist, int v) {
                this.dist = dist;
                this.v = v;
            }
            public int compareTo(Item that) {
                return Long.compare(this.dist, that.dist);
            }
        }
    }
    public static class FastScanner {
        BufferedReader br;
        StringTokenizer st;
        public FastScanner(Reader in) {
            br = new BufferedReader(in);
        }
        public FastScanner() {
            this(new InputStreamReader(System.in));
        }
        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }
        int nextInt() {
            return Integer.parseInt(next());
        }
        long nextLong() {
            return Long.parseLong(next());
        }
        double nextDouble() {
            return Double.parseDouble(next());
        }
        String readNextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
        int[] readIntArray(int n) {
            int[] a = new int[n];
            for (int idx = 0; idx < n; idx++) {
                a[idx] = nextInt();
            }
            return a;
        }
    }
}