#include <iostream>
#include <vector>
#include <climits>

using namespace std;

struct edge { int cap, to, rev; };

int dfs(vector<vector<edge>> &A, vector<bool> &U, int s, int t, int f)
{
        if (s == t)
                return f;
        U[s] = true;
        for (auto &e: A[s]) {
                if (!e.cap || U[e.to])
                        continue;
                int d = dfs(A, U, e.to, t, min(e.cap, f));
                if (d > 0) {
                        e.cap -= d;
                        A[e.to][e.rev].cap += d;
                        return d;
                }
        }
        return 0;
}

int main(int argc, char **argv)
{
        int V, E;
        cin >> V >> E;
        vector<vector<edge>> A(V);
        for (int i = 0; i < E; i++) {
                int u, v, c;
                cin >> u >> v >> c;
                A[u].push_back({c, v, (int)A[v].size()});
                A[v].push_back({0, u, (int)A[u].size()-1});
        }
        int sum = 0;
        while (true) {
                vector<bool> U(V);
                int d = dfs(A, U, 0, V-1, INT_MAX);
                if (!d)
                        break;
                sum += d;
        }
        cout << sum << endl;
        return 0;
}