Example

Input

3 3 1 2 4
1 2
2 3
3 1


Output

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

int n, m, a, b, c;
std::vector<int> from[64]; 

void Load() {
  std::cin >> n >> m >> a >> b >> c;
  for(int i = 0; i < m; ++i) {
    int s, t;
    scanf("%d %d", &s, &t);
    s -= 1; t -= 1;
    from[s].push_back(t);
  }
}

bool cango_a[64][64];
bool cango_b[64][64];
bool cango_c[64][64];

void calc1(bool xs[64], int r) {
  if( r == 0 ) return;
  bool next[64] = {};
  for(int i = 0; i < n; ++i) {
    if( xs[i] ) {
      for(int j = 0; j < (int)from[i].size(); ++j) {
        next[from[i][j]] = true;
      }
    }
  }
  for(int i = 0; i < n; ++i) {
    xs[i] = next[i];
  }
  calc1(xs, r - 1);
}

void Init() {
  for(int i = 0; i < n; ++i) {
    cango_a[i][i] = true;
    calc1(cango_a[i], a);
  }
  for(int i = 0; i < n; ++i) {
    cango_b[i][i] = true;
    calc1(cango_b[i], b);
  }
  for(int i = 0; i < n; ++i) {
    cango_c[i][i] = true;
    calc1(cango_c[i], c);
  }
}

int main() {
  Load();
  Init();
  // for(int i = 0; i < n; ++i) {
  //   for(int j = 0; j < n; ++j) {
  //     printf("%d ", cango_a[i][j]);
  //   }
  //   puts("");
  // }
  int dist[64];
  for(int i = 0; i < 64; ++i) dist[i] = (1 << 30);
  dist[n-1] = 0;
  
  for(;;) {
    bool end = true;
    int neari = -1;
    int neardist = (1 << 30);
    for(int i = 0; i < n; ++i) {
      if( dist[i] != (1 << 30) ) continue;
      int A, B, C;
      A = B = C = -1;
      int mm = (1 << 30);
      mm = (1 << 30);
      for(int j = 0; j < n; ++j) {
        if( cango_a[i][j] and dist[j] != (1 << 30) ) {
          if( dist[j] < mm ) {
            mm = dist[j];
            A = j;
          }
        }
      }
      mm = (1 << 30);
      for(int j = 0; j < n; ++j) {
        if( cango_b[i][j] and dist[j] != (1 << 30) ) {
          if( dist[j] < mm ) {
            mm = dist[j];
            B = j;
          }
        }
      }
      mm = (1 << 30);
      for(int j = 0; j < n; ++j) {
        if( cango_c[i][j] and dist[j] != (1 << 30) ) {
          if( dist[j] < mm ) {
            mm = dist[j];
            C = j;
          }
        }
      }
      if( not ( A != -1 and B != -1 and C != -1 ) ) continue;
      int d = std::max(dist[A], std::max(dist[B], dist[C])) + 1;
      if( neardist > d ) {
        neardist = d;
        neari = i;
        end = false;
      }
    }
    if( end ) break;
    dist[neari] = neardist;
  }

  if( dist[0] == (1 << 30) ) {
    printf("IMPOSSIBLE\n");
  }
  else {
    printf("%d\n", dist[0]);
  }
    
  return 0;
}