Example

Input

3 3 1 2 4
1 2
2 3
3 1


Output

IMPOSSIBLE
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi=vector<int>;
using vvi=vector<vi>;
#define rep(i,n) for(int i=0;i<n;i++)
#define all(a) a.begin(),a.end()

vvi matmul(vvi a, vvi b){
	int n=a.size();
	vector<ll> c(n,0),d(n,0);
	vvi r(n,vi(n,0));
	rep(i,n)rep(j,n){
		c[i]=c[i]*2+a[i][j];
		d[j]=d[j]*2+b[i][j];
	}
	rep(i,n)rep(j,n){
		r[i][j]=!!(c[i]&d[j]);
	}
	return r;
}

vector<vvi> memo(101);
vvi matpow(vvi a,int p){
	if(memo[p].size()==0)
		memo[p]=(p&1)?matmul(matpow(a,p-1),a):matmul(matpow(a,p/2),matpow(a,p/2));
	return memo[p];
}

int main(){
	int n,m,a[3];
	while(cin>>n>>m>>a[0]>>a[1]>>a[2]){
		vvi z(n,vi(n,0)), e=z;
		rep(_,m){
			int p,q; cin>>p>>q;
			e[p-1][q-1]=1;
		}
		fill(all(memo),vvi());
		memo[1]=e;

		vector<vvi> d(3);
		rep(p,3) d[p]=matpow(e,a[p]);
		
		vi g(n,0), ng(n,0);
		g[n-1]=1;
		rep(t,1000){
			bool next=0;
			fill(all(ng),0);
			rep(i,n) if(!g[i]){
				bool ok=1,r;
				rep(p,3) [&]{r=0; rep(j,n) r|=(g[j]&d[p][i][j]); ok&=r;}();
				if(ok) ng[i]=next=1;
			}
			if(!next){
				cout<<"IMPOSSIBLE"<<endl;
				break;
			} else if(ng[0]){
				cout<<t+1<<endl;
				break;
			}
			rep(i,n)g[i]|=ng[i];
		}
	}
	return 0;
}

