#include<cstdio>
#include<sstream>
#include<cstdlib>
#include<cctype>
#include<cmath>
#include<algorithm>
#include<set>
#include<queue>
#include<stack>
#include<list>
#include<iostream>
#include<fstream>
#include<numeric>
#include<string>
#include<vector>
#include<cstring>
#include<map>
#include<iterator>
#include<bitset>
using namespace std;
#define pf          printf
#define pb          push_back
#define sf          scanf
#define itr         iterator
#define Max         1e9+1
//#define lli         long long
#define PI         3.14159265358979323846

int fact(int n){
  return (n == 1 || n == 0) ? 1 : fact(n - 1) * n;
}

template<class T>
T gcd(T a,T b){
        if(a%b==0){return b;}
        else{ gcd(b,a%b);}
}

//take the values of trogonometric function in degree
double sinD(double x){return sin(x*(PI/180));}
double cosD(double x){return cos(x*(PI/180));}

//return inverse of Trigonometric function in degree
double acosD(double x){return acos(x)*(180/PI);}
double asinD(double x){return asin(x)*(180/PI);}


void sb(long long num){// Show Binary
    string bin =  bitset<32>(num).to_string();
    for(int i=4;i<=36;i+=5)
    bin.insert(i," ");
    cout << bin<<" = "<<num<<"\n";
}
void sbtd(string binary) {// show Binary to decimal
     unsigned long ul = bitset<32>(binary).to_ulong();
     cout<< ul<<"\n";
}

bool checkBit(int N,int pos){
    return (bool)(N&(1<<pos));
}

//convert a num in to string
template <class T>
string nts(T n){
	stringstream ss;
	ss << n;
	return ss.str();
}
/*********************debuggers*************************************************/
#define debug_array(a,n) for(int i=0;i<n;i++) cout<< #a<<'['<<i<<']'<<':'<< a[i]<<' '; cout<<"\n";
/******************************************************************************/

struct parent{
    int p_trac[108];
    bool reach;
};
parent bfs(int s,long long int r_graph[108][108],int t){
 parent dummy;
 int v[108]={0,0,0,0,0};
 queue<int> q;
 v[s]=1;
 q.push(s);
 while(!q.empty()){
    int s=q.front();
    //pf("%d\n",s);
    q.pop();
    for(int i=1;i<=t;i++){
        if(v[i]!=1 && r_graph[s][i]>0 ){
            //pf("\n-%d-\n",i);
            q.push(i);
            v[i]=1;
            dummy.p_trac[i]=s;
        }
    }
 }

if(v[t]==1){
    dummy.reach=true;
    return dummy;
}
dummy.reach=false;
return dummy;

}

void flow(int s,long long int r_graph[108][108],int t){

    parent p =bfs(1,r_graph,t);
    long long int mnf=Max;
    long long int tot=0;
    int u;
    while(p.reach==true){
        //find min flow
        for(int v=t;v!=1;v=u){
            u=p.p_trac[v];
            if(r_graph[u][v]<mnf){
                mnf=r_graph[u][v];
              //  cout<<mnf<<"\n";
            }
        }
         for(int v=t;v!=1;v=u){
            u=p.p_trac[v];
            r_graph[u][v]-=mnf;
            r_graph[v][u]+=mnf;

         }

        tot+=mnf;
       // cout<<"["<<mnf<<"]\n";
        mnf=Max;
        p =bfs(1,r_graph,t);

    }

    //cout<<tot<<"\n";
    pf("%lld\n",tot);
}

int main(){

    long long int r_graph[108][108];
    int n,e;
    scanf("%d%d",&n,&e);
    for(int i=0;i<e;i++){
        int a,b;
        long long int c;
        //cin>>a>>b>>c;
        scanf("%d%d%lld",&a,&b,&c);
        r_graph[a+1][b+1]+=c;
        //r_graph[b][a]+=c;
    }

    flow(1,r_graph,n);

    /*
    parent t = bfs(1,r_graph,n);
    for(int i=1;i<=n;i++){
        cout<<t.p_trac[i]<<" ";
    }
    */
    return 0;
}



Measured memory_bytes: 3328