Example

Input

3 3 1 2 4
1 2
2 3
3 1


Output

IMPOSSIBLE
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<queue>

using namespace std;

#define reps(i,f,n) for(int i=f;i<int(n);i++)
#define rep(i,n) reps(i,0,n)
#define pb push_back

const int N = 55;
const int T = 111;
const int INF = 300000000;

int n,m,a,b,c;

int dp[T][N][N];
int edge[N][N];


int main(){
  cin>>n>>m>>a>>b>>c;

  rep(i,N)rep(j,N)rep(k,T)dp[k][i][j] = INF;
  rep(i,N)rep(j,N)edge[i][j] = INF;

  rep(i,m){
    int t,u;
    cin>>t>>u;
    edge[t][u] = 1;
    dp[1][t][u] = 1;
  }

  reps(i,2,T){
    reps(j,1,n+1){
      reps(k,1,n+1){
	reps(p,1,n+1){
	  if(dp[i-1][j][p]!=INF && edge[p][k]!=INF){
	    dp[i][j][k] = 1;
	  }
	}
      }
    }
  }

  int check[N][3]={0};
  int visit[N]={0};

  typedef pair<int,int> pii;
  queue<pii> que;
  que.push(pii(n,0));
  check[n][0] = check[n][1] = check[n][2] = 1;

  while(!que.empty()){


    pii U = que.front();
    que.pop();

    int u = U.first;

    if(visit[u]!=0)continue;
    visit[u]=1;


    if(U.first==1){
      printf("%d\n",U.second);
      return 0;
    }

    reps(i,1,n+1){
      bool hitted = false;      
      if(dp[a][i][u]==1){
	check[i][0] = 1;
	hitted = true;
      }

      if(dp[b][i][u]==1){	
	check[i][1]=1;
	hitted = true;
      }
      if(dp[c][i][u]==1){
	check[i][2]=1;
	hitted = true;
      }


      if(hitted){
	bool ok = true;
	rep(j,3)if(check[i][j]!=1)ok=false;
	if(ok)que.push(pii(i,U.second+1));
      }
    }
  }

  puts("IMPOSSIBLE");

  /*
  rep(i,10){
    printf("%d\n",i);

    reps(j,1,n+1){
      reps(k,1,n+1){
	if(dp[i][j][k]!=INF) printf("%2d ",dp[i][j][k]);
	else printf("oo ");
      }puts("");
    }
  }
  */
  
}