Example

Input

3 3 1 2 4
1 2
2 3
3 1


Output

IMPOSSIBLE
#include<iostream>
#include<cstdio>
#include<vector>
#include<string>
#include<functional>
#include<queue>
#include <iomanip>
#include<map>
#include<limits>
#include<cmath>
#include<algorithm>
#include<bitset>
#include<utility>
#include<complex>
#include<cstdlib>
#include<set>
#include<cctype>

#define DBG cerr << '!' << endl;
#define REP(i,n) for(int (i) = (0);(i) < (n);++i)
#define rep(i,s,g) for(int (i) = (s);(i) < (g);++i)
#define rrep(i,s,g) for(int (i) = (s);i >= (g);--(i))
#define PB push_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {for(int i = 0;i < (n);i++)cerr << v[i] << ' ';cerr << endl << endl;}
#define SHOW2d(v,i,j) {for(int aaa = 0;aaa < i;aaa++){for(int bbb = 0;bbb < j;bbb++)cerr << v[aaa][bbb] << ' ';cerr << endl;}cerr << endl;}
#define ALL(v) v.begin(),v.end()

using namespace std;

typedef long long ll;
typedef vector<int> iv;
typedef vector<iv> iiv;
typedef vector<string> sv;

vector<vector<bool> > A(51,vector<bool>(51));
vector<vector<bool> > B(51,vector<bool>(51));
vector<vector<bool> > C(51,vector<bool>(51));
vector<vector<bool> > Y(51,vector<bool>(51));
vector<vector<bool> > mp(51,vector<bool>(51));

int main()
{
	int n,m,a,b,c;
	cin >> n >> m>> a >> b >> c;
	
	REP(i,m)
	{
		int u,v;
		cin >> u >> v;
		u--;v--;
		mp[u][v] = true;
	}
	
	Y = mp;
	REP(i,max(a,max(b,c)))
	{
		vector<vector<bool> > Z(51,vector<bool>(51));

		if(i+1 == a)A = Y;
		if(i+1 == b)B = Y;
		if(i+1 == c)C = Y;


		REP(i,n)REP(j,n)REP(k,n)
		{
			Z[i][j] = Z[i][j] | ( Y[i][k] & mp[k][j]);
		}
		Y = Z;
	}
	
	//SHOW2d(A,n+1,n+1);
	//SHOW2d(B,n+1,n+1);
	//SHOW2d(C,n+1,n+1);
	
	set<int> goal;
	goal.insert(n-1);
	
	for(int ans = 1;;ans++)
	{
		set<int> nw;
		REP(i,n)
		{
			if(!goal.count(i))
			{
				bool aa = false;
				bool bb = false;
				bool cc = false;
				REP(j,n)
				{
					if(goal.count(j))
					{
						if(A[i][j])aa = true;
						if(B[i][j])bb = true;
						if(C[i][j])cc = true;
					}
				}
				if(aa&&bb&&cc)nw.insert(i);
			}
		}
		
		if(nw.empty())
		{
			cout << "IMPOSSIBLE" << endl;
			return 0;
		}
		
		goal.insert(ALL(nw));
		if(goal.count(0))
		{
			cout << ans << endl;
			return 0;
		}
	}
	
	return 0;
}