// iostream is too mainstream
#include <cstdio>
// bitch please
#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <cmath>
#include <iomanip>
#define dibs reserve
#define OVER9000 123456789
#define ALL_THE(CAKE,LIE) for(auto LIE =CAKE.begin(); LIE != CAKE.end(); LIE++)
#define tisic 47
#define soclose 1e-8
#define chocolate win
// so much chocolate
#define patkan 9
#define ff first
#define ss second
#define abs(x) ((x < 0)?-(x):x)
#define uint unsigned int
#define dbl long double
using namespace std;
// mylittledoge
int main() {
cin.sync_with_stdio(0);
cin.tie(0);
int N,M;
cin >> N >> M;
vector< vector<int> > G(N,vector<int>(N,OVER9000));
for(int i =0; i < M; i++) {
int a,b,c;
cin >> a >> b >> c;
G[a][b] =G[b][a] =min(G[a][b],c);}
vector< vector<int> > D =G;
for(int i =0; i < N; i++) D[i][i] =0;
for(int k =0; k < N; k++)
for(int i =0; i < N; i++) for(int j =0; j < N; j++)
D[i][j] =min(D[i][j],D[i][k]+D[k][j]);
vector< vector<int> > F(2*N,vector<int>(2*N,0));
for(int i =1; i < N-1; i++) F[2*i][2*i+1] =1;
F[0][1] =F[2*N-2][2*N-1] =N+1;
for(int i =0; i < N; i++) for(int j =0; j < N; j++) if(G[i][j] < OVER9000)
if(D[0][i]+D[j][N-1]+G[i][j] == D[0][N-1])
F[2*i+1][2*j] =N+1;
int f =0;
while(true) {
vector<int> ako(2*N,-1);
queue<int> q;
q.push(0);
ako[0] =0;
while(!q.empty()) {
for(int i =0; i < 2*N; i++) if(F[q.front()][i] > 0 && ako[i] == -1) {
ako[i] =q.front();
q.push(i);}
q.pop();}
if(ako[2*N-1] == -1) break;
f++;
int akt =2*N-1;
while(akt > 0) {
F[akt][ako[akt]]++;
F[ako[akt]][akt]--;
akt =ako[akt];}
}
if(f < N) cout << f << "\n";
else cout << "IMPOSSIBLE\n";
return 0;}
// look at my code
// my code is amazing
Ly8gaW9zdHJlYW0gaXMgdG9vI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