Example

Input

3 3 1 2 4
1 2
2 3
3 1


Output

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

using namespace std;

#define int long long
#define FR first
#define SC second
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define reps(i, f, n) for(int i = (int)(f); i < (int)(n); i++)
#define each(a, b) for(auto& a : b)

typedef pair<int, int> P;

const int inf = 1LL << 55;
const int mod = 1e9 + 7;

// ??´?????????????????°???????????§

signed main()
{
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);
  
  int n, m, a[3];
  cin >> n >> m;
  rep(i, 3) cin >> a[i];  
  
  bool rG[101][55][55] = {{{false}}}; 
  rep(i, m) {
    int u, v; cin >> u >> v;
    u--, v--;
    rG[0][v][u] = true;
  }

  // rG[i][j][k] := i????????£?????????j??????k????????????????????????????????????????????????
  reps(i, 1, 101) rep(j, n) rep(k, n) rep(l, n) {
    rG[i][k][l] |= rG[i-1][k][j] & rG[0][j][l]; // ??????????????????
  }

  queue<int> que;
  que.push(n-1);
  int d[55]; memset(d, -1, sizeof(d));
  d[n-1] = 0;
  int bit[55] = {0};
  while(!que.empty()) {
    int now = que.front(); que.pop();
    if(now == 0) {
      cout << d[now] << endl;
      return 0;
    }
    rep(i, 3) rep(j, n) {
      if(!rG[a[i]-1][now][j]) continue;
      bit[j] |= 1<<i;
      if(bit[j] == (1<<3)-1 && d[j] == -1) {
	d[j] = d[now] + 1;
	que.push(j);
      }
    }
  }
  puts("IMPOSSIBLE");
  
  return 0;
}