Example

Input

3 3 1 2 4
1 2
2 3
3 1


Output

IMPOSSIBLE
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#include <set>
using namespace std;

void listup(int cur, int lim, int mark, vector<vector<int> > &adj, vector<int> &ret){
    set<int> vlist;
    vlist.insert(cur);
    set<int>::iterator itr;
    for(int i=0; i<lim; i++){
        set<int> newset;
        for(itr = vlist.begin(); itr!=vlist.end(); itr++){
            int node = *itr;
            for(int j=0; j<(int)adj[node].size(); j++){
                newset.insert(adj[node][j]);
            }
        }
        vlist = newset;
    }
    for(itr = vlist.begin(); itr!=vlist.end(); itr++){
        ret[*itr] |= mark;
    }
}

int main(){
    int n,m,a,b,c;
    cin >> n >> m >> a >> b >> c;
    vector<vector<int> > revadj(n+1);
    for(int i=0; i<m; i++){
        int u,v;
        cin >> u >> v;
        revadj[v].push_back(u);
    }
    
    vector<bool> used(n+1, false), isnew(n+1, false);
    used[n] = true; isnew[n] = true;
    int ans = -1;
    int turn = 0;
    vector<int> cand(n+1, 0);
    while(1){
        if(used[1]){
            ans = turn;
            break;
        }
        for(int i=1; i<=n; i++){
            if(!isnew[i]) continue;
            listup(i, a, 1, revadj, cand);
            listup(i, b, 2, revadj, cand);
            listup(i, c, 4, revadj, cand);
        }
        isnew = vector<bool>(n+1, false);
        bool update=false;
        for(int i=1; i<=n; i++){
            if(cand[i] == 7 && !used[i]){
                used[i] = true;
                update = true;
                isnew[i] = true;
            }
        }
        if(!update) break;
        turn++;
    }
    
    if(ans==-1){
        cout << "IMPOSSIBLE" << endl;
    }else{
        cout << ans << endl;
    }
    return 0;
}