Problem: problem

There are $ V $ islands, numbered $ 0, 1, ..., V-1 $, respectively. There are $ E $ bridges, numbered $ 0, 1, ..., E-1 $, respectively. The $ i $ th bridge spans island $ s_i $ and island $ t_i $ and is $ c_i $ wide.

The AOR Ika-chan Corps (commonly known as the Squid Corps), which has a base on the island $ 0 $, is small in scale, so it is always being killed by the Sosu-Usa Corps (commonly known as the Sosuusa Corps) on the island $ V-1 $. .. One day, the squid group got the information that "the Sosusa group will attack tomorrow." A large number of Sosusa's subordinates move across the island from the Sosusa's base, and if even one of their subordinates reaches the Squid's base, the Squid will perish ...

Therefore, the squid group tried to avoid the crisis by putting a road closure tape on the bridge to prevent it from passing through. The length of the tape used is the sum of the widths of the closed bridges. Also, if all the subordinates of the Sosusa group always pass through a bridge with a width of $ 1 $, the squid group can ambush there to prevent them from passing through the Sosusa group.

The length of the tape it holds is $ 10 ^ 4 $. Considering the future, I would like to consume as little tape as possible. Find the minimum length of tape used to keep Sosusa's subordinates from reaching the squid's base. However, if the tape is not long enough and you are attacked by all means, output $ -1 $.



output

Output the minimum length of tape used to prevent Sosusa's subordinates from reaching the Squid's base. However, if the tape is not long enough and you are attacked by all means, output $ -1 $. Also, output a line break at the end.

Example

Input

4 4
0 1 3
0 2 4
1 3 1
2 3 5


Output

4

Solution (in CPP):

Solution:
#include <bits/stdc++.h>
#define FOR(i,a,b) for(ut i=(a);i<(int)(b);i++)
#define REP(i,b) FOR(i,0,b)
#define ALL(c) c.begin(),c.end()
#define PB push_back
#define cat //cout << __LINE__ << endl;
using namespace std;
typedef long long LL;
typedef long double ld;
typedef int ut;
typedef vector<ut> VI;
typedef pair<ut,ut> pr;
typedef pair<ut,pr> ppr;
typedef vector<pr> Vpr;
typedef vector<ppr> Vppr;
typedef priority_queue<pr,Vpr,greater<pr> > PQ;
const int SIZE=2*1e5;
const int INF=1LL<<30;
const LL p=7+1e9;
const int rev=10000;
const int rev2=rev*2;
Vpr edges[SIZE];
int dist[SIZE];
ld nokori[SIZE];
LL V,E;
ld dfs(int now,ld nowflow){
	ld ans=0;
	if(now==V-1){
		return nowflow;
	}
	REP(i,edges[now].size()){
		int next=edges[now][i].first;
		int noko=edges[now][i].second;
		if(dist[next]!=dist[now]+1) continue;
		if(nokori[noko]==0) continue;
		ld inc=dfs(next,min(nokori[edges[now][i].second],nowflow));
		nowflow-=inc;
		nokori[noko]-=inc;
		nokori[(noko+rev)%rev2]+=inc;
		ans+=inc;
	}
	return ans;
}
int bfs(){
	queue<int> qu;
	dist[0]=0;
	qu.push(0);
	while(!qu.empty()){
		int now=qu.front();
		qu.pop();
		REP(i,edges[now].size()){
			int next=edges[now][i].first;
			ld noko=nokori[edges[now][i].second];
			if(noko>0 && dist[next]==INF){
				dist[next]=dist[now]+1;
				qu.push(next);
			}
		}
	}
	return dist[V-1];
}
ld dinic(){
	ld ans=0;
	while(true){
		int dists;
		REP(i,V) dist[i]=INF;
		dists=bfs();
		//cout << dists << endl;
		if(dists==INF) return ans;
		ans+=dfs(0,INF);	
		//cout << ans << endl;
	}

}
LL solve(){
	cin >> V >> E;
	LL s,t;
	ld c;
	REP(i,E){
		cin >> s >> t >> c;
		if(c==1) c-=0.00001;
		nokori[i]=c;
		nokori[i+rev]=c;
		edges[s].PB(pr(t,i));
		edges[t].PB(pr(s,i+rev));
	}
	ld ans=dinic();
	return (int)ans;
}
int main(){
	int ans=solve();
	if(ans>1e4){
		cout << -1 << endl;
	}
	else{
		cout << ans << endl;
	}
	return 0;
}