Example

Input

3 3 1 2 4
1 2
2 3
3 1


Output

IMPOSSIBLE
#include <iostream>
#include <vector>
#include <cstring>

using namespace std;

int main(){
	int n, m, a, b, c;
	int visit[101][50];
	int step[50];
	while(cin >> n >> m >> a >> b >> c){
		vector< vector<int> > g(n);
		for(int i=0;i<m;i++){
			int p, q;
			cin >> p >> q;
			g[p-1].push_back(q-1);
		}
		vector< vector<int> > reachA(n), reachB(n), reachC(n);
		for(int i=0;i<n;i++){
			memset(visit, 0, sizeof(visit));
			visit[0][i] = 1;
			for(int j=0;j<100;j++){
				for(int k=0;k<n;k++){
					if(!visit[j][k]) continue;
					for(int& t : g[k]) visit[j+1][t] = 1;
				}
			}
			for(int j=0;j<n;j++){
				if(visit[a][j]) reachA[i].push_back(j);
				if(visit[b][j]) reachB[i].push_back(j);
				if(visit[c][j]) reachC[i].push_back(j);
			}
		}
		for(int i=0;i<n-1;i++) step[i] = 10000;
		step[n-1] = 0;
		while(true){
			bool update = false;
			for(int i=0;i<n;i++){
				int sa = 10000, sb = 10000, sc = 10000;
				for(int t : reachA[i]) sa = min(sa, step[t]);
				for(int t : reachB[i]) sb = min(sb, step[t]);
				for(int t : reachC[i]) sc = min(sc, step[t]);
				int nextStep = max(sa, max(sb, sc)) + 1;
				if(nextStep < step[i]){
					update = true;
					step[i] = nextStep;
				}
			}
			if(!update) break;
		}
		if(step[0] == 10000) cout << "IMPOSSIBLE" << endl;
		else cout << step[0] << endl;
	}
}