Example

Input

3 3 1 2 4
1 2
2 3
3 1


Output

IMPOSSIBLE
#include<bits/stdc++.h>

#define REP(i,s,n) for(int i=s;i<n;++i)
#define rep(i,n) REP(i,0,n)

using namespace std;

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef VVI matrix;

vector<vector<int> > identity(int n) {
  vector<vector<int> > A(n,vector<int>(n,0));
  for(int i=0;i<n;i++) A[i][i] = 1;
  return A;
}

matrix multi(const matrix& A,const matrix& B)
{
  matrix C(A.size(),vector<int>(B[0].size()));
  for(int i=0;i<C.size();++i)
    for(int j=0;j<C[i].size();++j)
      for(int k=0;k<A[i].size();++k) {
	C[i][j] += A[i][k]*B[k][j];
	C[i][j] = min(1,C[i][j]);
      }
  return C;
}

matrix pow(const matrix& A,int e)
{
  return !e?identity(A.size()):
    (e%2?multi(A,pow(A,e-1)):pow(multi(A,A),e/2));
}

int n,m,steps[3];
vector<int> G[51];
int par[51];

int find(int x) {
  if( x == par[x] ) return x;
  return par[x] = find(par[x]);
}

void unite(int a,int b) {
  a = find(a), b = find(b);
  if( a != b ) par[a] = b;
}

vector<int> reachable_nodes(int step) {
  vector<int> ret(n,0);
  vector<vector<int> > mat(n,vector<int>(n,0));
  rep(i,n) rep(j,(int)G[i].size()) mat[i][G[i][j]] = 1;
  mat = pow(mat,step);
  rep(sp,n) if( find(n-1) == find(sp) ) rep(i,n) if( mat[sp][i] ) ret[i] = 1;
  return ret;
}

void compute() {
  rep(i,n) par[i] = i;
  bool update = true;
  int answer = 0;
  while( update ) {
    update = false;
    vector<int> nodes[3];
    rep(i,3) nodes[i] = reachable_nodes(steps[i]);
    rep(i,n) {
      if( nodes[0][i] && nodes[1][i] && nodes[2][i] ) {
	if( find(n-1) != find(i) )  {
	  update = true;
	  unite(n-1,i);
	}
      }
    }
    ++answer;
    if( find(0) == find(n-1) ) break;
  }
  if( find(0) == find(n-1) ) {
    cout << answer << endl;
  } else {
    puts("IMPOSSIBLE");
  }
}

int main() {
  cin >> n >> m;
  rep(i,3) cin >> steps[i];
  rep(i,m) {
    int u,v;
    cin >> u >> v;
    --u, --v;
    G[v].push_back(u);
  }
  compute();
  return 0;
}