Example

Input

3 3 1 2 4
1 2
2 3
3 1


Output

IMPOSSIBLE
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <vector>
#include <cassert>
#include <string>
#include <set>
#include <queue>
#include <cmath>
using namespace std;
typedef long long LL;
const int N = 1005;

int f[55][55];
int g[55][3];
int vis[105][55][55];
int dp[55];
int dp1[55][3];

int C[3];

int main() {
    int n, m;
    scanf("%d%d%d%d%d", &n, &m, &C[0], &C[1], &C[2]);
    
    for (int i = 1; i <= m; ++i) {
        int x, y;
        scanf("%d%d", &x, &y);
        f[y][x] = 1;
    }
    for (int i = 1; i <= n; ++i)
        vis[0][i][i] = 1;
    for (int k = 0; k < 100; ++k)
        for (int i = 1; i <= n; ++i)
            for (int j = 1; j <= n; ++j)
                if (vis[k][i][j]) {
                    for (int l = 1;  l <= n; ++l)
                        vis[k + 1][i][l] |= vis[k][i][j] & f[j][l];
                }
    queue<int> que;
    memset(dp, 63, sizeof(dp));
    memset(dp1, 63, sizeof(dp1));
    dp[n] = 0;
    dp1[n][0] = dp1[n][1] = dp1[n][2] = 0; 
    que.push(n);
    while (!que.empty()) {
        int x = que.front(); que.pop();
        //out << x << endl;
        for (int i = 1; i <= n; ++i)
            if (dp[i] > n * n) {
                for (int j = 0; j < 3; ++j)
                    if (vis[C[j]][x][i])
                        dp1[i][j] = min(dp[x] + 1, dp1[i][j]);
                if (dp1[i][0] <= n * n && dp1[i][1] <= n * n && dp1[i][2] <= n * n) {
                    dp[i] = 0;
                    for (int j = 0; j < 3; ++j)
                        dp[i] = max(dp[i], dp1[i][j]);
                    que.push(i);
                }
            }
    }
    if (dp[1] > n * n) puts("IMPOSSIBLE");
    else printf("%d\n", dp[1]);
    return 0;
}