Example

Input

3 3 1 2 4
1 2
2 3
3 1


Output

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

using namespace std;
const int INF = 1000000000;
int n, m, a[3];
int go[110][60][60], ok[60];
int matrix[60][60], dp[60][3], dp2[60];
int main(){
//freopen("in.txt", "r", stdin);
    scanf("%d %d %d %d %d", &n, &m, &a[0], &a[1], &a[2]);
    for (int i = 1; i <= m; ++ i){
        int u, v; scanf("%d %d", &u, &v);
        matrix[v][u] = 1;
    }
    for (int i = 1; i <= n; ++ i) go[0][i][i] = 1;
    for (int k = 1; k <= 100; ++ k){
        for (int i = 1; i <= n; ++ i){
            for (int j = 1; j <= n; ++ j){
                if (go[k - 1][i][j] == 0) continue;
                for (int l = 1; l <= n; ++ l){
                    //if (k == 1 && i == 8 && l == 1) printf("%d\n", j);
                    go[k][i][l] |= go[k - 1][i][j] & matrix[j][l];
                }
            }
        }
    }
    for (int i = 1; i <= n; ++ i){
        for (int j = 0; j < 3; ++ j){
            dp[i][j] = INF;
        }
        dp2[i] = INF;
    }

    queue <int> q;
    q.push(n); dp2[n] = 0;
    while (!q.empty()){
        int h = q.front(); q.pop();

        for (int i = 0; i < 3; ++ i){
            for (int j = 1; j <= n; ++ j){
                if (go[a[i]][h][j]){
                    if (dp2[h] + 1 < dp[j][i]){

                        ok[j] |= 1 << i;
                        dp[j][i] = dp2[h] + 1;

                        if (ok[j] == 7){
                            dp2[j] = *max_element(dp[j], dp[j] + 3);
                            q.push(j);
                        }
                    }
                }
            }
        }
    }
    //printf("%d\n", go[0][8][1]);
    int ans = dp2[1];
    if (ans == INF) puts("IMPOSSIBLE");
    else{
        printf("%d\n", ans);
    }
}