Example

Input

3 3 1 2 4
1 2
2 3
3 1


Output

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

using namespace std;

int N, M, A[3];
bool graph[50][50];
bool v[101][50][50];

void Calculation()
{
  cin >> N >> M;
  for(int i = 0; i < 3; i++) {
    cin >> A[i];
  }
  sort(begin(A), end(A));

  while(M--) {
    int U, V;
    cin >> U >> V;
    --U, --V;
    graph[V][U] = v[0][V][U] = true;
  }

  for(int l = 1; l <= A[2]; l++) {
    for(int k = 0; k < N; ++k) {
      for(int i = 0; i < N; ++i) {
        for(int j = 0; j < N; ++j) {
          v[l][i][j] |= v[l - 1][i][k] & graph[k][j];
        }
      }
    }
  }

  int min_cost[50], bit[50] = {};
  queue< int > que;
  memset(min_cost, -1, sizeof(min_cost));
  que.emplace(N - 1);
  min_cost[N - 1] = 0;
  while(!que.empty()) {
    int p = que.front();
    que.pop();
    if(p == 0) {
      cout << min_cost[p] << endl;
      return;
    }
    for(int i = 0; i < 3; i++) {
      for(int j = 0; j < N; j++) {
        if(!v[A[i] - 1][p][j]) continue;
        bit[j] |= 1 << i;
        if(bit[j] == 7 && min_cost[j] == -1) {
          min_cost[j] = min_cost[p] + 1;
          que.emplace(j);
        }
      }
    }
  }
  cout << "IMPOSSIBLE" << endl;

}


int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  Calculation();
}