/*
Copyright 2012 Marek "p2004a" Rusinowski
Dinic's algorithm
*/
#include <cstdio>
#include <vector>
#include <queue>
#include <algorithm>
#define MAXN 10000
#define INF 0x7FFFFFFF
struct edge {
int dest, flow, sec;
edge(int _dest, int _flow, int _sec) : dest(_dest), flow(_flow), sec(_sec) {}
};
std::vector<edge> edges[MAXN];
int d[MAXN], n, m;
bool bfs(int s, int t) {
std::queue<int> queue;
queue.push(s);
std::fill(d, d + n, 0);
d[s] = 1;
while (!queue.empty()) {
int v = queue.front();
queue.pop();
for (int i = 0; i < (int) edges[v].size(); ++i) {
if (!d[edges[v][i].dest] && edges[v][i].flow > 0) {
d[edges[v][i].dest] = d[v] + 1;
queue.push(edges[v][i].dest);
}
}
}
return d[t];
}
int dfs(int v, int t, int min_c) {
if (v == t) {
return min_c;
}
int res = 0;
for (int i = 0; i < (int) edges[v].size(); ++i) {
if (d[edges[v][i].dest] == d[v] + 1 && edges[v][i].flow > 0) {
int y = dfs(edges[v][i].dest, t, std::min(min_c, edges[v][i].flow));
res += y;
edges[v][i].flow -= y;
edges[edges[v][i].dest][edges[v][i].sec].flow += y;
min_c -= y;
if (min_c == 0) {
break;
}
}
}
return res;
}
int maxflow(int s, int t) {
int res = 0;
while (bfs(s, t)) {
res += dfs(s, t, INF);
}
return res;
}
int main() {
int a, b, c;
scanf("%d %d", &n, &m);
for (int i = 0; i < m; ++i) {
scanf("%d %d %d", &a, &b, &c);
--a, --b;
edges[a].push_back(edge(b, c, edges[b].size()));
edges[b].push_back(edge(a, 0, edges[a].size() - 1));
}
int s, t;
scanf("%d %d", &s, &t);
printf("%d\n", maxflow(s - 1, t - 1));
return 0;
}
LyoKICBDb3B5cmlnaHQgMjAxMiBNYXJlayAicDIwMDRhIiBSdXNpbm93c2tpCiAgRGluaWMncyBhbGdvcml0aG0KKi8KI2luY2x1ZGUgPGNzdGRpbz4KI2luY2x1ZGUgPHZlY3Rvcj4KI2luY2x1ZGUgPHF1ZXVlPgojaW5jbHVkZSA8YW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