A flow network is a directed graph which has a $source$ and a $sink$. In a flow network, each edge $(u, v)$ has a capacity $c(u, v)$. Each edge receives a flow, but the amount of flow on the edge can not exceed the corresponding capacity. Find the maximum flow from the $source$ to the $sink$.

Constraints

* $2 \leq |V| \leq 100$
* $1 \leq |E| \leq 1000$
* $0 \leq c_i \leq 10000$

Input

A flow network is given in the following format.

$|V|\;|E|$
$u_0\;v_0\;c_0$
$u_1\;v_1\;c_1$
:
$u_{|E|-1}\;v_{|E|-1}\;c_{|E|-1}$



$|V|$, $|E|$ is the number of vertices and edges of the flow network respectively. The vertices in $G$ are named with the numbers 0, 1,..., $|V|-1$. The source is 0 and the sink is $|V|-1$.

$u_i$, $v_i$, $c_i$ represent $i$-th edge of the flow network. A pair of $u_i$ and $v_i$ denotes that there is an edge from $u_i$ to $v_i$ and $c_i$ is the capacity of $i$-th edge.

Output

Print the maximum flow.

Example

Input

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


Output

3
import java.util.LinkedList;
import java.util.Queue;
import java.util.Scanner;

public class Main {

    private static final double FLOATING_POINT_EPSILON = 1E-10;

    static class FlowEdge {
        final int v;
        final int w;
        final double capacity;
        double flow;

        FlowEdge(int v, int w, double capacity) {
            this.v = v;
            this.w = w;
            this.capacity = capacity;
            this.flow = 0.;
        }

        public double residualCapacity(int vertex) {
            if      (vertex == v) return flow;              // backward edge
            else if (vertex == w) return capacity - flow;   // forward edge
            else throw new IllegalArgumentException("invalid endpoint");
        }

        public void addResidualFlow(int vertex, double delta) {
            if (!(delta >= 0.0)) throw new IllegalArgumentException("Delta must be nonnegative");

            if      (vertex == v) flow -= delta;           // backward edge
            else if (vertex == w) flow += delta;           // forward edge
            else throw new IllegalArgumentException("invalid endpoint");

            // round flow to 0 or capacity if within floating-point precision
            if (Math.abs(flow) <= FLOATING_POINT_EPSILON)
                flow = 0;
            if (Math.abs(flow - capacity) <= FLOATING_POINT_EPSILON)
                flow = capacity;

            if (!(flow >= 0.0))      throw new IllegalArgumentException("Flow is negative");
            if (!(flow <= capacity)) throw new IllegalArgumentException("Flow exceeds capacity");
        }

        public String toString() {
            return v + "->" + w + " " + flow + "/" + capacity;
        }

        public int other(int vertex) {
            if      (vertex == v) return w;
            else if (vertex == w) return v;
            else throw new IllegalArgumentException("invalid endpoint");
        }
    }

    @SuppressWarnings("unchecked")
    static class FlowNetwork {
        private static final String NEWLINE = "\n";
        private int E = 0;

        final int V;
        final LinkedList<FlowEdge>[] adj;

        FlowNetwork(int V) {
            this.V = V;
            this.adj = new LinkedList[V];
            for (int v = 0; v < V; v++){
                adj[v] = new LinkedList<FlowEdge>();
            }
        }

        void addEdge(FlowEdge edge) {
            adj[edge.v].add(edge);
            adj[edge.w].add(edge);
            E++;
        }

        public Iterable<FlowEdge> adj(int v) {
            return adj[v];
        }

        public String toString() {
            StringBuilder s = new StringBuilder();
            s.append(V + " " + E + NEWLINE);
            for (int v = 0; v < V; v++) {
                s.append(v + ":  ");
                for (FlowEdge e : adj[v]) {
                    if (e.w != v) s.append(e + "  ");
                }
                s.append(NEWLINE);
            }
            return s.toString();
        }
    }

    static class FordFulkerson {
        private boolean[] marked;
        private FlowEdge[] edgeTo;
        double value;

        FordFulkerson(FlowNetwork G, int s, int t){
            value = 0.;
            while (hasAugmentingPath(G, s, t)) {

                // compute bottleneck capacity
                double bottle = Double.POSITIVE_INFINITY;
                for (int v = t; v != s; v = edgeTo[v].other(v)) {
                    bottle = Math.min(bottle, edgeTo[v].residualCapacity(v));
                }

                // augment flow
                for (int v = t; v != s; v = edgeTo[v].other(v)) {
                    edgeTo[v].addResidualFlow(v, bottle);
                }

                value += bottle;
            }
        }

        private boolean hasAugmentingPath(FlowNetwork G, int s, int t) {
            edgeTo = new FlowEdge[G.V];
            marked = new boolean[G.V];

            // breadth-first search
            Queue<Integer> queue = new LinkedList<>();
            queue.add(s);
            marked[s] = true;
            while (!queue.isEmpty() && !marked[t]) {
                int v = queue.poll();

                for (FlowEdge e : G.adj(v)) {
                    int w = e.other(v);

                    // if residual capacity from v to w
                    if (e.residualCapacity(w) > 0) {
                        if (!marked[w]) {
                            edgeTo[w] = e;
                            marked[w] = true;
                            queue.add(w);
                        }
                    }
                }
            }

            // is there an augmenting path?
            return marked[t];
        }

    }

    public static void main (String[] args){
        Scanner scanner = new Scanner(System.in);

        int V = scanner.nextInt();
        int E = scanner.nextInt();

        FlowNetwork network = new FlowNetwork(V);

        for (int e = 0; e < E; e++) {
            int v = scanner.nextInt();
            int w = scanner.nextInt();
            int c = scanner.nextInt();
            FlowEdge edge = new FlowEdge(v, w, c);
            network.addEdge(edge);
        }

//        System.out.println(network.toString());

        FordFulkerson ff = new FordFulkerson(network, 0, V - 1);

        System.out.println((int) ff.value);
    }
}

