Example

Input

3 3 1 2 4
1 2
2 3
3 1


Output

IMPOSSIBLE
#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;


enum Type{
	case_A,
	case_B,
	case_C,
};


int N,E;
int A,B,C;
vector<int> G[50],CAN_GO[50][3];
int min_turn[50];
bool table[101][50][50];


int main(){

	scanf("%d %d %d %d %d",&N,&E,&A,&B,&C);

	int maximum = max(max(A,B),C);

	int from,to;
	for(int loop = 0; loop < E; loop++){
		scanf("%d %d",&from,&to);
		from--;
		to--;
		G[from].push_back(to);
	}

	for(int i = 0; i <= maximum; i++){
		for(int a = 0; a < N; a++){
			for(int b = 0; b < N; b++)table[i][a][b] = false;
		}
	}

	for(int i = 0; i < N; i++){
		table[0][i][i] = true;
	}

	for(int i = 1; i <= maximum; i++){
		for(int start = 0; start < N; start++){
			for(int mid = 0; mid < N; mid++){

				if(!table[i-1][start][mid])continue;

				for(int k = 0; k < G[mid].size(); k++){ //50
					table[i][start][G[mid][k]] = true;
				}
			}
		}
	}

	for(int i = 0; i < N; i++){
		for(int k = 0; k < N; k++){
			if(table[A][i][k] == true){
				CAN_GO[i][case_A].push_back(k);
			}
			if(table[B][i][k] == true){
				CAN_GO[i][case_B].push_back(k);
			}
			if(table[C][i][k] == true){
				CAN_GO[i][case_C].push_back(k);
			}
		}
	}

	for(int i = 0; i < N-1; i++)min_turn[i] = BIG_NUM;
	min_turn[N-1] = 0;

	bool Updated;
	int work[3],max_turn;

	while(true){
		Updated = false;

		for(int i = 0; i < N; i++){
			for(int k = 0; k < 3; k++)work[k] = BIG_NUM;
			for(int k = 0; k < CAN_GO[i][case_A].size(); k++)work[0] = min(work[0],min_turn[CAN_GO[i][case_A][k]]);
			for(int k = 0; k < CAN_GO[i][case_B].size(); k++)work[1] = min(work[1],min_turn[CAN_GO[i][case_B][k]]);
			for(int k = 0; k < CAN_GO[i][case_C].size(); k++)work[2] = min(work[2],min_turn[CAN_GO[i][case_C][k]]);

			max_turn = max(max(work[0],work[1]),work[2]);
			if(max_turn == BIG_NUM)continue;
			max_turn++;

			if(min_turn[i] > max_turn){
				min_turn[i] = max_turn;
				Updated = true;
			}
		}
		if(!Updated)break;
	}

	if(min_turn[0] == BIG_NUM){
		printf("IMPOSSIBLE\n");
	}else{
		printf("%d\n",min_turn[0]);
	}

	return 0;
}

