Example

Input

3 3 1 2 4
1 2
2 3
3 1


Output

IMPOSSIBLE
#include <bits/stdc++.h>
using namespace std;

#define rep(i,n) for(int i=0; i<n; i++)
typedef long long ll;
typedef pair<int,int> pii;

vector<int> conn[51];
vector< vector< set<int> > > path;

bool visit[51][101];
void dfs(int p, int k, set<int>& st) {
	if(k==0) {
		st.insert(p);
		return;
	}
	if(visit[p][k]) return;
	visit[p][k] = true;

	for(int i=0; i<conn[p].size(); i++) {
		if( !visit[conn[p][i]][k-1] ) {
			dfs(conn[p][i], k-1, st);
		}
	}
}

int main() {
	int n,m,a,b,c;
	cin >> n >> m >> a >> b >> c;
	rep(i,m) {
		int u,v;
		cin >> u >> v;
		conn[u].push_back(v);
	}
	path.resize(n+1);
	for(int i=1; i<=n; i++) {
		path[i].resize(3);
		memset(visit, 0, sizeof(visit));
		dfs(i, a, path[i][0]);
		memset(visit, 0, sizeof(visit));
		dfs(i, b, path[i][1]);
		memset(visit, 0, sizeof(visit));
		dfs(i, c, path[i][2]);
	}

	bool changed = true;
	set<int> marked;
	marked.insert(n);
	int res = -1;
	int cnt[101]={};
	memset(cnt, -1, sizeof(cnt));
	cnt[n] = 0;
	int lp = 1;
	while(changed) {
		changed = false;
		vector<int> adds;
		for(int i=1; i<=n; i++) {
			if(marked.find(i) != marked.end()) continue;
			int mark = 0;
			rep(j,3) {
				bool found = false;
				for(set<int>::iterator it=path[i][j].begin(); it!=path[i][j].end(); it++) {
					if( marked.find(*it) != marked.end() ) {
						found = true;
					}
				}
				if(found) {
					mark++;
				}
			}
			if(mark == 3) {
				adds.push_back(i);
				changed = true;
				cnt[i] = lp;
			}
		}
		lp++;
		rep(i, adds.size()) {
			marked.insert(adds[i]);
		}
	}
	if(cnt[1] == -1)
		cout << "IMPOSSIBLE" << endl;
	else
		cout << cnt[1] << endl;

	return 0;
}