Example

Input

3 3 1 2 4
1 2
2 3
3 1


Output

IMPOSSIBLE
#include <iostream>
#include <vector>
#include <algorithm>

#define REP(i, n) for(int i=0; i<(n); i++)

using namespace std;

int zmin(int a, int b){
	if( a==0 ) return b;
	return min(a,b);
}

int main(){
	int n, m, a, b, c, u, t;
	vector<int> v[55];

	cin>>n>>m>>a>>b>>c;
	REP(i, m){
		cin>>u>>t;
		v[t].push_back(u);
	}
	if(a>b) swap(a,b);
	if(b>c) swap(c,b);
	if(a>b) swap(a,b);
	int l[3] = {a,b,c};

	int goal[55] = {}, gcount=0;
	goal[n] = 1;
	while(1){
		int reach[55][2]={};
		REP(i,n+1) if(goal[i]) reach[i][0] = goal[i];
		int len[55][3]={};
		REP(i,c+1){
			REP(j,n) reach[j+1][(i+1)%2] = 0;	// ????????????
			REP(j,n){
				if( reach[j+1][i%2] ){
					for(auto to: v[j+1]){
						reach[to][(i+1)%2] = zmin(reach[to][(i+1)%2], reach[j+1][i%2]);
					}
					if(i == a) len[j+1][0] = reach[j+1][i%2]+1;
					if(i == b) len[j+1][1] = reach[j+1][i%2]+1;
					if(i == c) len[j+1][2] = reach[j+1][i%2]+1;
				}
			}
			//REP(j,n) cout << reach[j+1][i%2] << " ";
			//cout << endl;
		}
		int count=0;
		REP(j,n){
			if( len[j+1][0]>0 && len[j+1][1]>0 && len[j+1][2]>0 ){
				goal[j+1] = zmin( goal[j+1], max( len[j+1][0], max(len[j+1][1], len[j+1][2]) ) );
			}
			if( goal[j+1] ) count++;
		}
		//cout << "count:" << count << endl;
		//cout << "goal: ";
		//REP(j,n) cout << goal[j+1] << " ";
		//cout << endl;
		if( gcount == count ) break;
		gcount = count;
	}
	if( goal[1] == 0 ) cout << "IMPOSSIBLE" << endl;
	else cout << (goal[1]-1) << endl;

	return 0;
}