#include <bits/stdc++.h>

using namespace std;

#define MAX_V 100
#define INF 1e9

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

int V,E;
vector<edge> G[MAX_V];
bool used[MAX_V];

void add_edge(int from,int to,int cap){
    G[from].push_back((edge){to,cap,static_cast<int>(G[to].size())});
    G[to].push_back((edge){from,0,static_cast<int>(G[from].size()-1)});
}

int dfs(int v,int t,int f){
    if(v == t) return f;
    used[v] = true;
    for(int i = 0 ; i < (int)G[v].size() ; i++){
        edge &e = G[v][i];
        if(!used[e.to] && e.cap > 0){
            int d = dfs(e.to,t, min(f, e.cap));
            if(d > 0){
                e.cap -= d;
                G[e.to][e.rev].cap += d;
                return d;
            }
        }
    }
    return 0;
}

int max_flow(int s,int t){
    int flow = 0;
    for(;;){
        memset(used,false,sizeof(used));
        int f = dfs(s,t,INF);
        if(f == 0) return flow;
        flow += f;
    }
}

int main(){
    int a,b,c;
    cin >> V >> E;
    for(int i = 0 ; i < E ; i++){
        cin >> a >> b >> c;
        add_edge(a,b,c);
    }
    cout << max_flow(0,V-1) << endl;
    return 0;
}
