#include <iostream>
#include <vector>
#include <queue>
#define INF (1 << 30)
using namespace std;
bool bfs(vector<vector<int>>& Graph,int s,int t,vector<int>& parent) {
	vector<bool> visited(t + 1, false);
	queue<int> q;
	q.push(s); visited[s] = true; parent[s] = -1;
	while (!q.empty()) {
		int u = q.front(); q.pop();
		for (int v = 0; v < t+1;v++) {
			if (visited[v] == false && Graph[u][v] > 0) {
				q.push(v);	parent[v] = u;	visited[v] = true;
			}
		}
	}
	return (visited[t] == true);
}
int fordFulkerson(vector<vector<int>>& Graph, int s, int t) { 
	int u, v;
	vector<int> parent(t + 1);
	int max_flow = 0;
	while (bfs(Graph, s, t, parent)) {
		int path_flow = INF;
		for (v = t; v != s; v = parent[v]) {
			u = parent[v];	path_flow = min(path_flow, Graph[u][v]);
		}

		for (v = t; v != s; v = parent[v]) {
			u = parent[v];
			Graph[u][v] -= path_flow;
			Graph[v][u] += path_flow;
		}

		max_flow += path_flow;
	}
	return max_flow;
}
int main() {
	int V, E; cin >> V >> E;
	vector<vector<int>> G(V,vector<int>(V,0));	//V x V   init:0
	for (int i = 0; i < E;i++) {
		int u, v, c; cin >> u >> v >> c;
		G[u][v] = c;
	}
	cout << fordFulkerson(G, 0, V - 1) << endl;
	return 0;
}