Example

Input

3 3 1 2 4
1 2
2 3
3 1


Output

IMPOSSIBLE
#include <bits/stdc++.h>
using namespace std;

int X[4];
bool R[51][51][101];
bool W[51];
vector < int > G[51];

int main() {

//    freopen("rin.txt", "r", stdin);

    int n, m, i, j, k;
    int a, b, c;

    cin>>n>>m>>X[0]>>X[1]>>X[2];
    while (m--) {
        cin>>i>>j;
        G[i].push_back(j);
        R[i][j][1] = 1;
    }
    for (i = 1; i <= n; i++) R[i][i][0] = 1;
    for (int len = 2; len <= 100; len++) {
        for (i = 1; i <= n; i++) {
            for (j = 1; j <= n; j++) {
                if (R[i][j][len-1] == 1) {
                    for (k = 0; k < G[j].size(); k++) {
                        int v = G[j][k];
                        R[i][v][len] = 1;
                    }
                }
            }
        }
    }

    W[n] = 1;
    int steps = 0;
    while (true) {
        vector < int > nw;
        for (i = 1; i <= n; i++) {
            if (W[i] == 1) continue;
            bool f = true;
            for (j = 0; j < 3; j++) {
                for (k = 1; k <= n; k++) {
                    if (R[i][k][X[j]] == 1 && W[k] == 1) break;
                }
                f &= (k <= n);
            }
            if (f) nw.push_back(i);
        }
        if (nw.size() == 0) break;
        steps++;
        for (k = 0; k < nw.size(); k++) W[nw[k]] = 1;
        if (W[1] == 1) break;
    }

    if (W[1] == 1) cout<<steps<<endl;
    else cout<<"IMPOSSIBLE"<<endl;


    return 0;
}

