Example

Input

3 3 1 2 4
1 2
2 3
3 1


Output

IMPOSSIBLE
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
const int INF = (int)1e9 + 7;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main() {
    int n, m; cin >> n >> m;
    vector<int> a(3);
    for (int &ai: a) cin >> ai;
    vector<vector<int>> g(n);
    while (m--) {
        int u, v; cin >> u >> v; u--, v--;
        g[u].emplace_back(v);
    }
    // nxt[s][i] := s から a[i] で到達できる頂点
    vector<vector<vector<int>>> nxt(n, vector<vector<int>>(3));
    const int MAX = 100;
    for (int s = 0; s < n; s++) {
        vector<vector<int>> visited(n, vector<int>(MAX + 1));
        visited[s][0] = true;
        for (int cnt = 0; cnt < MAX; cnt++) {
            for (int u = 0; u < n; u++) if (visited[u][cnt]) {
                for (int v: g[u]) visited[v][cnt + 1] = true;
            }
        }
        for (int i = 0; i < 3; i++) {
            for (int u = 0; u < n; u++) if (visited[u][a[i]]) {
                nxt[s][i].emplace_back(u);
            }
        }
    }
    vector<int> d(n, INF);
    d.back() = 0;
    bool update = true;
    while (update) {
        update = false;
        for (int u = 0; u < n; u++) {
            vector<int> mi(3, INF);
            for (int i = 0; i < 3; i++) {
                for (int v: nxt[u][i]) chmin(mi[i], d[v]);
            }
            int ma = *max_element(mi.begin(), mi.end()) + 1;
            if (chmin(d[u], ma)) update = true;
        }
    }
    if (d[0] == INF) {
        cout << "IMPOSSIBLE" << endl;
    } else {
        cout << d[0] << endl;
    }
    return 0;
}
