Example

Input

3 3 1 2 4
1 2
2 3
3 1


Output

IMPOSSIBLE
#include <iostream>
#define rep(i,n) for(int i=0;i<n;++i)
using namespace std;

const int inf=1<<20;

bool dist[110][55][55];
int all[55],nall[55];

int main(void){
	int n,m,a,b,c;
	cin >> n >> m >> a >> b >> c;
	rep(i,m){
		int u,v;
		cin >> u >> v;
		dist[1][u-1][v-1]=true;
	}

	for(int d=2;d<=100;++d)rep(k,n)rep(i,n)rep(j,n) dist[d][i][j]|=(dist[d-1][i][k]&dist[1][k][j]);
	
	all[n-1]=7;
	
	int ans=-1;
	for(int turn=1;turn<=100;++turn){
		rep(i,n) nall[i]=all[i];
		rep(i,n)rep(j,n)if(all[j]==7&&dist[a][i][j]) nall[i]|=1;
		rep(i,n)rep(j,n)if(all[j]==7&&dist[b][i][j]) nall[i]|=2;
		rep(i,n)rep(j,n)if(all[j]==7&&dist[c][i][j]) nall[i]|=4;

		if(nall[0]==7){
			ans=turn;
			break;
		}
		rep(i,n) all[i]=nall[i];
	}

	if(ans==-1)
		cout << "IMPOSSIBLE" << endl;
	else
		cout << ans << endl;

	return 0;
}