#include <bits/stdc++.h>
#define pb push_back
using namespace std;
const int INF=0x3f3f3f3f;
const int maxn=105;

struct Edge {
	int from,to,cap,flow;
	Edge(int u,int v,int c,int f):from(u),to(v),cap(c),flow(f) {}
};

int n,m;
vector<Edge>edges;
vector<int>G[maxn];
int a[maxn],p[maxn];

int maxflow (int s,int t) {
	int flow=0;
	while (1) {
		memset(a,0,sizeof(a));
		queue<int>q;
		q.push(s);
		a[s]=INF;
		while (q.size()) {
			int x=q.front(); q.pop();
			for (int id:G[x]) {
				Edge &e=edges[id];
				if (!a[e.to] && e.cap>e.flow) {
					p[e.to]=id;
					a[e.to]=min(a[x],e.cap-e.flow);
					if (a[t]) break;
					q.push(e.to);
				}
			}
		}
		if (!a[t]) break;
		for (int u=t;u!=s;u=edges[p[u]].from) {
			edges[p[u]].flow+=a[t];
			edges[p[u]^1].flow-=a[t];
		}
		flow+=a[t];
	}
	return flow;
}

int main() {
	cin>>n>>m;
	for (int i=0;i<m;i++) {
		int u,v,c; cin>>u>>v>>c;
		edges.pb(Edge(u,v,c,0));
		edges.pb(Edge(v,u,0,0));
		int id=edges.size()-2;
		G[u].pb(id);
		G[v].pb(id+1);
	}
	cout<<maxflow(0,n-1)<<'\n';
}

