#include <bits/stdc++.h>

using ll = long long;
using namespace std;
constexpr ll inf = 1e9;
constexpr ll mod = 1e9+7;

struct Edge {
    int to;
    int cap;
    int rev;
};
vector<Edge> edges[101];
bool used[101] = {false};

int dfs(int v, int t, int f) {
    if (v == t) return f;
    used[v] = true;
    for (auto&& edge : edges[v]) {
        if (used[edge.to] || edge.cap <= 0) continue;
        int d = dfs(edge.to, t, min(f, edge.cap));
        if (d > 0) {
            edge.cap -= d;
            edges[edge.to][edge.rev].cap += d;
            return d;
        }
    }
    return 0;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(NULL);

    int V, E;
    cin>>V>>E;
    for (int e = 0; e < E; e++) {
        int U, V, C;
        cin>>U>>V>>C;
        edges[U].push_back(Edge{V, C, (int)edges[V].size()});
        edges[V].push_back(Edge{U, 0, (int)edges[U].size()-1});
    }

    int flow = 0;
    while (1) {
        fill(begin(used), end(used), false);
        int f = dfs(0, V-1, inf);
        if (f == 0) break;
        flow += f;
    }
    cout<<flow<<endl;

    return 0;
}
