Example

Input

3 3 1 2 4
1 2
2 3
3 1


Output

IMPOSSIBLE
#include<bits/stdc++.h>
#define MAX 51
#define inf (1e8)
using namespace std;

int n,m,a,b,c;
vector<int> re[MAX];
bool can[MAX][MAX][MAX*2]={};

int main()
{
  int x,y;

  cin>>n>>m>>a>>b>>c;

  for(int i=0;i<m;i++){
    cin>>x>>y;
    x--;y--;
    re[y].push_back(x);
  }

  for(int i=0;i<n;i++){
    queue<int> q;
    q.push(i);
    for(int j=1;j<MAX*2;j++){
      vector<int> v;
      while(!q.empty()){
	int now=q.front();
	q.pop();
	for(int k=0;k<re[now].size();k++){
	  int next=re[now][k];
	  if(!can[i][next][j]){
	    can[i][next][j]=true;
	    v.push_back(next);
	  }
	}
      }
      for(int k=0;k<v.size();k++)q.push(v[k]);
    }
  }
 
  queue<int> q;
  q.push(n-1);
  int dis[n];
  bool A[n],B[n],C[n];
  for(int i=0;i<n;i++){
    dis[i]=inf;
    A[i]=B[i]=C[i]=false;
  }
  dis[n-1]=0;
  while(!q.empty()){
    int now=q.front();
    q.pop();
    if(now==0)break;
    for(int i=0;i<n;i++){
      if(can[now][i][a])A[i]=true;
      if(can[now][i][b])B[i]=true;
      if(can[now][i][c])C[i]=true;

      if(A[i] && B[i] && C[i] && dis[i]==inf){
	dis[i]=dis[now]+1;
	q.push(i);
      }
    }
  }
  if(dis[0]==inf)cout<<"IMPOSSIBLE"<<endl;
  else cout<<dis[0]<<endl;
  return 0;
}