#include <iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<string>
#include<queue>
#define N 205
#define INF 0x7fffffff
#define M 505
using namespace std;
int head[N],cnt;
struct edge{
int to,next,cap;
}e[M];
void init(){
cnt=0;
memset(head,-1,sizeof(head));
}
void addedge(int u,int v,int cap){
e[cnt].to=v;e[cnt].cap=cap;e[cnt].next=head[u];head[u]=cnt++;
e[cnt].to=u;e[cnt].cap=0;e[cnt].next=head[v];head[v]=cnt++;
}
int pre[N],pe[N];
queue<int> q;
int EK(int s,int t){
int max_flow=0;
while(true){
while(!q.empty()){
q.pop();
}
memset(pre,-1,sizeof(pre));
q.push(s);
while(!q.empty()){
int u=q.front();
q.pop();
for(int i=head[u];i!=-1;i=e[i].next){
int v=e[i].to;
if(pre[v]==-1&&e[i].cap>0){
q.push(v);
pre[v]=u;
pe[v]=i;
}
}
if(pre[t]!=-1)
break;
}
if(pre[t]==-1)
break;
int aug=INF;
for(int v=t;v!=s;v=pre[v]){
aug=min(aug,e[pe[v]].cap);
}
for(int v=t;v!=s;v=pre[v]){
e[pe[v]].cap-=aug;
e[pe[v]^1].cap+=aug;
}
max_flow+=aug;
}
return max_flow;
}
int main()
{
int n,m,u,v,cap,ans;
while(~scanf("%d%d",&m,&n)){
init();
while(m--){
scanf("%d%d%d",&u,&v,&cap);
addedge(u,v,cap);
}
ans=EK(1,n);
printf("%d\n",ans);
}
return 0;
}