#include《cstdio》
#include《cstring》
#define MAXN 205
#define MAXM 205
#define INF 1<<30
struct edge
{
int v,next,flow;
};
int dep[MAXN],s,t,ans,h[MAXN],u,v,flow,m,n,tot;
edge list[MAXM];
int min(int a,int b)
{
return (a
}
void AddList(int u,int v,int flow)
{
tot++;
list[tot].next=h[u];
list[tot].v=v;
list[tot].flow=flow;
h[u]=tot;
}
void init()
{
freopen("EXMaxFlow.in","r",stdin);
freopen("EXMaxFlow.out","w",stdout);
scanf("%d %d",&m,&n);
for (int i=1;i<=m;i++)
{
scanf("%d %d %d",&u,&v,&flow);
AddList(u,v,flow);
AddList(v,u,0);
}
s=1; t=n;
}
int BFS()
{
int q[MAXN*MAXN],head,tail;
head=1; tail=2; q[1]=s; dep[s]=1;
while (head!=tail)
{
for (int x=h[q[head]];x!=0;x=list[x].next)
{
if (dep[list[x].v]==0 && list[x].flow>0)
{
dep[list[x].v]=dep[q[head]]+1;
q[tail++]=list[x].v;
}
}
head++;
}
if (dep[t]==0) return 0;
else return 1;
}
int DFS(int now,int RouteMinFlow)
{
int OldRouteMinFlow=0;
if (RouteMinFlow<=0 || now==t) return RouteMinFlow;
for (int x=h[now];x!=0;x=list[x].next)
{
if (dep[list[x].v]==dep[now]+1)
{
int temp=DFS(list[x].v,min(RouteMinFlow,list[x].flow));
list[x+1].flow+=temp;
list[x].flow-=temp;
RouteMinFlow-=temp;
OldRouteMinFlow+=temp;
if (RouteMinFlow==0) break;
}
}
return OldRouteMinFlow;
}
int main()
{
init();
while (BFS()==1) { ans+=DFS(s,INF); memset(dep,0,sizeof(dep)); }
printf("%d",ans);
}