Example

Input

3 3 1 2 4
1 2
2 3
3 1


Output

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

using namespace std;

namespace {

    typedef double real;
    typedef long long ll;

    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 << "]";
    }
    template<class T> istream& operator>>(istream& is, vector<T>& vs) {
        for (auto it = vs.begin(); it != vs.end(); it++) is >> *it;
        return is;
    }

    int N, M, A, B, C;
    vector< vector<int> > G;
    void input() {
        cin >> N >> M >> A >> B >> C;
        G.resize(N);
        for (int i = 0; i < M; i++) {
            int u, v; cin >> u >> v; u--; v--;
            G[u].push_back(v);
        }
    }

    void solve() {
        vector<bool> fin(N, false);
        fin[N - 1] = true;
        for (int t = 1; t <= N; t++) {
            vector<bool> pfin = fin;
            for (int k = 0; k < N; k++) {
                bool used[N][101];
                memset(used, 0, sizeof(used));
                queue< pair<int, int> > Q;
                Q.push(make_pair(k, 0));
                used[k][0] = true;
                while (!Q.empty()) {
                    auto c = Q.front(); Q.pop();
                    int v = c.first, d = c.second;
                    if (d >= 100) continue;
                    for (int i = 0; i < G[v].size(); i++) {
                        int u = G[v][i];
                        if (!used[u][d + 1]) {
                            Q.push(make_pair(u, d + 1));
                            used[u][d + 1] = true;
                        }
                    }
                }
                int flag = 0;
                for (int i = 0; i < N; i++) {
                    if (pfin[i] && used[i][A]) flag |= 1;
                    if (pfin[i] && used[i][B]) flag |= 2;
                    if (pfin[i] && used[i][C]) flag |= 4;
                }
                if (flag == 7) fin[k] = true;
            }
            pfin = fin;
            if (fin[0]) {
                cout << t << endl;
                return;
            }
        }
        cout << "IMPOSSIBLE" << endl;
    }
}

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