Example

Input

3 3 1 2 4
1 2
2 3
3 1


Output

IMPOSSIBLE
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
using namespace std;
typedef vector<int> vec;
typedef vector<vec> mat;

int main(){
  int n,m,l[3];
  cin >> n >> m >> l[0] >> l[1] >> l[2];
  vector<mat> adj(100, mat(n,vec(n,0)) );

  rep(i,m){
    int s,t;
    cin >> s >> t; s--; t--;
    adj[0][t][s] = 1;
  }

  rep(x,99){
    rep(i,n)rep(j,n)rep(k,n){
      adj[x+1][i][j] |= adj[x][i][k] && adj[0][k][j];
    }
  }

  vector<int> d(n,-1), can(n,0);
  d[n-1] = 0; can[n-1] = 7;
  queue<int> q;
  q.push(n-1);

  while(q.size()){
    int v = q.front(); q.pop();

    rep(x,3){
      rep(u,n){
	if(adj[l[x]-1][v][u]){
	  can[u] |= 1<<x;
	  if(can[u] == 7 && d[u]<0){
	    d[u] = d[v] + 1;
	    q.push(u);
	  }
	}
      }
    }
  }

  if(d[0] < 0){
    cout << "IMPOSSIBLE" << endl;
  }else{
    cout << d[0] << endl;
  }
}