Example

Input

3 3 1 2 4
1 2
2 3
3 1


Output

IMPOSSIBLE
#include "bits/stdc++.h"

using namespace std;

template <typename T>
void printv(const vector<T> &v)
{
    int sz = v.size();
    for (int i = 0; i < sz; i++)
    {
        cout << v[i] << " \n"[i == sz - 1];
    }
}

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);

    int n, m, a, b, c;
    cin >> n >> m >> a >> b >> c;
    vector<vector<int>> g(n, vector<int>(n, 0));
    for (int i = 0; i < m; i++)
    {
        int u, v;
        cin >> u >> v;
        u--;
        v--;
        g[u][v] = 1;
    }
    vector<vector<int>> id(n, vector<int>(n, 0));
    for (int i = 0; i < n; i++)
        id[i][i] = 1;
    vector<vector<vector<int>>> reach;
    reach.emplace_back(id);
    reach.emplace_back(g);
    for (int t = 2; t <= 100; t++)
    {
        vector<vector<int>> nxt(n, vector<int>(n, 0));
        for (int i = 0; i < n; i++)
        {
            for (int j = 0; j < n; j++)
            {
                for (int k = 0; k < n; k++)
                {
                    nxt[i][j] |= reach[t - 1][i][k] * g[k][j];
                }
            }
        }
        reach.emplace_back(nxt);
    }
    int ret = 0;
    bool update = true;
    vector<int> st(n, 0);
    st[n - 1] = 1;
    while (update)
    {
        // printv(st);
        update = false;
        ret++;
        set<int> cand;
        for (int i = 0; i < n; i++)
        {
            if (st[i])
                continue;
            bool fa = false, fb = false, fc = false;
            for (int j = 0; j < n; j++)
            {
                if (!st[j])
                    continue;
                if (reach[a][i][j])
                    fa = true;
                if (reach[b][i][j])
                    fb = true;
                if (reach[c][i][j])
                    fc = true;
            }
            if (fa && fb && fc)
                cand.emplace(i);
        }
        if (cand.size() != 0)
            update = true;
        for (auto v : cand)
        {
            st[v] = 1;
        }
        if (st[0])
        {
            cout << ret << endl;
            return 0;
        }
        if (!update)
        {
            cout << "IMPOSSIBLE" << endl;
            return 0;
        }
    }
}

