Example

Input

3 3 1 2 4
1 2
2 3
3 1


Output

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

using namespace std;
const int INF = 1e9;


int main(){
  int N, M;
  vector<int> as(3);
  cin >> N >> M >> as[0] >> as[1] >> as[2];
  vector<vector<int>> G(N);
  for(int i=0;i<M;++i){
	int u, v; cin >> u >> v;
	--u, --v;
	G[u].push_back(v);
  }

  vector<set<int>> memo[3];
  for(int k=0;k<3;++k)
	for(int i=0;i<N;++i){
	  set<int> buf[2];
	  int crt = 0, nxt = 1;
	  buf[crt].insert(i);
	  for(int n=0;n<as[k];++n){
		buf[nxt].clear();
		for(int x: buf[crt])
		  for(int to: G[x])
			buf[nxt].insert(to);
		swap(crt, nxt);
	  }
	  memo[k].push_back(buf[crt]);
	}

  vector<int> dist(N, INF);
  dist[N-1] = 0;
  for(int i=0;i<N;++i){
	for(int j=0;j<N;++j){
	  int prv = dist[j];
	  dist[j] = 0;
	  for(int k=0;k<3;++k){
		int tmp = INF;
		for(int x: memo[k][j])
		  if(x != j)
			tmp = min(tmp, dist[x]+1);
		dist[j] = max(dist[j], tmp);
	  }
	  dist[j] = min(dist[j], prv);
	}
  }

  //for(int i=0;i<N;++i) cout << i << " " << dist[i] << endl;
  if(dist[0] >= INF || dist[0] < 0)
	cout << "IMPOSSIBLE" << endl;
  else
	cout << dist[0] << endl;

  return 0;
}