Example

Input

3 3 1 2 4
1 2
2 3
3 1


Output

IMPOSSIBLE
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using P = pair<int, int>;
const double eps = 1e-8;
const ll MOD = 1000000007;
const int INF = INT_MAX / 2;
const ll LINF = LLONG_MAX / 2;
template <typename T1, typename T2>
void chmax(T1 &a, const T2 &b) {
  if(a < b) a = b;
}
template <typename T1, typename T2>
void chmin(T1 &a, const T2 &b) {
  if(a > b) a = b;
}
template<typename T>
void printv(const vector<T>& s) {
  for(int i=0;i<(int)(s.size());++i) {
    cout << s[i];
    if(i != (int)(s.size())-1) cout << " ";
  }
  cout << "\n";
}
template<typename T1, typename T2>
ostream& operator<<(ostream &os, const pair<T1, T2> p) {
  os << p.first << ":" << p.second;
  return os;
}
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  int n, m; vi v(3); cin >> n >> m >> v[0] >> v[1] >> v[2];
  vvi g(n);
  for(int i=0;i<m;++i) {
    int a, b; cin >> a >> b;
    a--; b--;
    g[a].push_back(b);
  }
  vector<vector<set<int>>> V(3, vector<set<int>>(n));
  vector<set<int>> tmp(n);
  for(int i=0;i<n;++i) {
    tmp[i].insert(i);
  }
  int now = 0;
  while(now <= max(v[0], max(v[1], v[2]))) {
    vector<set<int>> nxt(n);
    for(int i=0;i<n;++i) {
      for(auto &e: tmp[i]) {
        for(int j=0;j<(int)(g[e].size());++j) {
          nxt[i].insert(g[e][j]);
        }
      }
    }
    now++;
    if(now == v[0]) {
      V[0] = nxt;
    }
    if(now == v[1]) {
      V[1] = nxt;
    }
    if(now == v[2]) {
      V[2] = nxt;
    }
    tmp = nxt;
  }
  vector<int> d(n, -1);
  d[n-1] = 0;
  for(int i=0;i<n;++i) {
    vi nxt(n, -1);
    for(int j=0;j<n;++j) {
      for(int k=0;k<3;++k) {
        int tmp = INF;
        for(auto &e: V[k][j]) {
          if(d[e] == -1) continue;
          chmin(tmp, d[e] + 1);
        }
        chmax(nxt[j], tmp);
      }
      if(nxt[j] == -1) nxt[j] = d[j];
      else if(d[j] != -1) chmin(nxt[j], d[j]);
      if(nxt[j] == INF) nxt[j] = -1;
    }
    d = nxt;
  }
  if(d[0] == -1) {
    cout << "IMPOSSIBLE" << endl;
  } else {
    cout << d[0] << endl;
  }
}

