Example

Input

3 3 1 2 4
1 2
2 3
3 1


Output

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

#define for_(i,a,b) for(int i=(a);i<(b);++i)

int n, m, d[3];
vector< vector< int > > edge;

set< int > nextStep(set< int >& cur) {
	set< int > ret;
	for (int v : cur) for (int u : edge[v]) ret.insert(u);
	return ret;
}

void solve() {
	set< int > target = {n-1};
	for_(i,0,n) {
		set< int > cand[3];
		for_(j,0,3) {
			cand[j] = target;
			for_(t,0,d[j]) cand[j] = nextStep(cand[j]);
		}
		
		for_(v,0,n) {
			bool flag = true;
			for_(j,0,3) flag &= (cand[j].count(v) == 1);
			if (flag) target.insert(v);
		}
		
		if (target.count(0)) {
			cout << i+1 << endl;
			return;
		}
	}
	puts("IMPOSSIBLE");
}

int main() {
	cin >> n >> m;
	for_(i,0,3) cin >> d[i];
	
	edge.assign(n, vector< int >());
	for_(i,0,m) {
		int u, v;
		cin >> u >> v;
		--u; --v;
		edge[v].push_back(u);
	}
	
	solve();
}