Example

Input

3 3 1 2 4
1 2
2 3
3 1


Output

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

using namespace std;

namespace {

    template<class T> ostream& operator<<(ostream& os, const vector<T>& vs) {
        if (vs.empty()) return os << "[]";
        os << "[" << vs[0];
        for (int i = 1; i < vs.size(); i++) os << " " << vs[i];
        return os << "]";
    }

    const int MAX_N = 51;

    int N, M, A, B, C;
    bool G[MAX_N][MAX_N];
    void input() {
        cin >> N >> M >> A >> B >> C;
        memset(G, 0, sizeof(G));
        for (int i = 0; i < M; i++) {
            int u, v;
            cin >> u >> v;
            u--; v--;
            G[u][v] = true;
        }
    }

    const int INF = 1<<28;

    vector<bool> find(int v, int n) {
        vector<bool> xs(N, false);
        xs[v] = true;
        for (int i = 0; i < n; i++) {
            vector<bool> ys(N, false);
            for (int j = 0; j < N; j++) {
                if (not xs[j]) continue;
                for (int k = 0; k < N; k++) {
                    if (G[j][k]) ys[k] = true;
                }
            }
            xs = ys;
        }
        return xs;
    }

    void solve() {
        vector<int> f(N, INF);
        f[N - 1] = 0;
        for (int n = 1; ; n++) {
            vector<int> prev = f;
            for (int i = 0; i < N; i++) {
                vector<bool> a = find(i, A);
                vector<bool> b = find(i, B);
                vector<bool> c = find(i, C);
                bool p = false, q = false, r = false;
                for (int j = 0; j < N; j++) {
                    if (a[j] && prev[j] < n) p = true;
                    if (b[j] && prev[j] < n) q = true;
                    if (c[j] && prev[j] < n) r = true;
                }
                if (p && q && r) {
                    f[i] = min(f[i], n);
                }
            }
            if (prev == f) break;
        }
        if (f[0] == INF) cout << "IMPOSSIBLE" << endl;
        else cout << f[0] << endl;
    }
}

int main() {
    input(); solve();
    return 0;
}