#include<stdio.h>
#include<stdlib.h>
#include<math.h>

typedef long long int int64;

#define MAX(a,b) ((a)>(b)?(a):(b))
#define MIN(a,b) ((a)<(b)?(a):(b))
#define ABS(a) ((a)>(0)?(a):-(a))

#define POS(i,j) ((i)*v+(j))

const int m=10000;
int flow(int source,int sink,int *g,int v){
  int used[100];
  int dp[100];
  int i;
  for(i=0;i<v;i++){
    used[i]=0;
    dp[i]=0;
  }
  dp[source]=m;
  int a[100];
  int len=0;
  while(dp[sink]==0){
    int max=0;
    int maxIndex=-1;
    for(i=0;i<v;i++){
      if(!used[i] && dp[i]>max){
	max=dp[i];
	maxIndex=i;
      }
    }
    if(max==0) return 0;
    used[maxIndex]=1;
    a[len++]=maxIndex;
    for(i=0;i<v;i++){
      dp[i]=MAX(dp[i],MIN(dp[maxIndex],g[POS(maxIndex,i)]));
    }
  }
  int f=dp[sink];
  int now=sink;
  for(i=len-1;now!=source;i--){
    int u=a[i];
    if(g[POS(u,now)]>=f){
      g[POS(u,now)]-=f;
      g[POS(now,u)]+=f;
      now=u;
    }
  }
  return f;
}

void run(void){
  int v,e;
  scanf("%d%d",&v,&e);
  int g[10000];
  int i;
  for(i=0;i<v*v;i++) g[i]=0;
  for(i=0;i<e;i++){
    int s,t,c;
    scanf("%d%d%d",&s,&t,&c);
    g[POS(s,t)]=c;
  }

  int sum=0;
  int f;
  while(f=flow(0,v-1,g,v),f>0) sum+=f;
  printf("%d\n",sum);
  return;
}

int main(void){
  run();
  return 0;
}

