Example

Input

3 3 1 2 4
1 2
2 3
3 1


Output

IMPOSSIBLE
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}

template<class T>
inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}

const long double EPS = 1e-10;
const long long INF = 1e18;
const long double PI = acos(-1.0L);
//const ll mod = 1000000007;
ll N, M, A[3];
vector<vector<int>> paths;
vector<vector<int>> inv;
vector<int> g[150][150];
int dist[150];
int reach[150];

set<int> f(set<int> from, int dist) {
    if(dist == 0) return from;
    set<int> tmp;
    for(auto u : from) {
        for(auto to : inv[u]) {
            tmp.insert(to);
        }
    }
    return f(tmp, dist - 1);
}

void bfs(int s) {
    for(int i = 0; i < N; i++) dist[i] = 1e9;
    dist[s] = 0;
    reach[s] = 7;
    queue<int> que;
    que.push(s);
    while(!que.empty()) {
        int now = que.front();
        que.pop();
        for(int i = 0; i < 3; i++) {
            for(auto to : g[now][i]) {
                reach[to] |= (1 << i);
                //cerr << now << " " << to << " " << i << endl;
                if(reach[to] == 7) {
                    if(chmin(dist[to], dist[now] + 1)) que.push(to);
                }
            }
        }
    }
}

int main() {
    cin >> N >> M;
    for(int i = 0; i < 3; i++) cin >> A[i];
    paths.resize(N);
    inv.resize(N);
    for(int i = 0; i < M; i++) {
        int u, v;
        cin >> u >> v;
        u--;
        v--;
        paths[u].push_back(v);
        inv[v].push_back(u);
    }
    for(int i = 0; i < N; i++) {
        for(int j = 0; j < 3; j++) {
            set<int> tmp;
            tmp.insert(i);
            auto st = f(tmp, A[j]);
            for(auto c : st) {
                g[i][j].push_back(c);
                //cerr << i << " " << j << " " << c << endl;
            }
        }
    }
    bfs(N - 1);
    if(dist[0] == 1e9) cout << "IMPOSSIBLE" << endl;
    else cout << dist[0] << endl;
    return 0;
}
