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,a,b) for(int i=a;i<b;i++)




#define INF INT_MAX/2
int N, M, A, B, C;
set<int> dp[101][50];
int dist[50];
// -----------------------------------------------------------
int main()
{
	cin >> N >> M >> A >> B >> C;
	
	rep(i,0,N) dp[0][i].insert(i);
	rep(i,0,M) 
	{
		int u, v; cin >> u >> v;
		u--; v--;
		dp[1][u].insert(v);
	}

    rep(i,2,101) rep(j,0,N)
    {
        for(set<int>::iterator ite = dp[i-1][j].begin();ite != dp[i-1][j].end();ite++) 
        {
            int ii = *ite;
            for(set<int>::iterator ite = dp[1][ii].begin();ite != dp[1][ii].end();ite++) dp[i][j].insert(*ite);
        }
    }
    
    rep(i,0,N) dist[i] = INF;
    dist[N - 1] = 0;
	bool con = true;
	while(con)
	{
        con = false;
        rep(i, 0, N)
        {
            int m = 0, mm;
            bool AA = false;
            mm = INF;
            for(set<int>::iterator ite = dp[A][i].begin();ite != dp[A][i].end();ite++) 
            {
                int j = *ite;
                if(dist[j] < INF)
                {
                    AA = true;
                    mm = min(mm, dist[j]);
                }
            }
            m = max(m,mm);

            bool BB = false;
            mm = INF;
            for(set<int>::iterator ite = dp[B][i].begin();ite != dp[B][i].end();ite++) 
            {
                int j = *ite;
                if(dist[j] < INF)
                {
                    BB = true;
                    mm = min(mm, dist[j]);
                }
            }
            m = max(m, mm);
            
            bool CC = false;
            mm = INF;
            for(set<int>::iterator ite = dp[C][i].begin();ite != dp[C][i].end();ite++) 
            {
                int j = *ite;
                if(dist[j] < INF)
                {
                    CC = true;
                    mm = min(mm, dist[j]);
                }
            }
            m = max(m, mm);
            
            if((AA && (BB && CC)) && m + 1 < dist[i])
            {
                dist[i] = m + 1;
                con = true;
            }
        }
	}
	
	//rep(i,0,N) cout << dist[i] << endl;
	
	if(dist[0] == INF)
	    cout << "IMPOSSIBLE" << endl;
	else
    	cout << dist[0] << endl;	
}