Example

Input

3 3 1 2 4
1 2
2 3
3 1


Output

IMPOSSIBLE
#include <iostream>
#include <stdio.h>
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <queue>
#include <algorithm>
#include <set>
#include <math.h>
#include <utility>
#include <stack>
#include <string.h>
#include <complex>
#include <bitset>
using namespace std;

const int INF = 1<<29;
const double EPS = 1e-8;
typedef vector<int> vec;
typedef pair<int,int> P;
typedef long long ll;


int main() {
    int n, m;
    cin >> n >> m;
    vec abc(3);
    cin >> abc[0] >> abc[1] >> abc[2];

    vector<vec> G(n);
    for(int i=0;i<m;i++){
        int u, v;
        cin >> u >> v;
        G[u-1].push_back(v-1);
    }

    bitset<50> cango[50][1001];
    for(int j=0;j<n;j++){
        cango[j][0].set(j);
        for(int k=0;k<G[j].size();k++){
            int to = G[j][k];
            cango[j][1].set(to);
        }
    }
    for(int i=2;i<=1000;i++){
        for(int j=0;j<n;j++){
            for(int k=0;k<G[j].size();k++){
                int to = G[j][k];
                cango[j][i] |= cango[to][i-1];
            }
        }
    }

    vector<bool> goal(n, false);
    goal[n-1] = true;
    for(int t=1;t<=n;t++){
        vector<bool> goal_new = goal;
        for(int i=0;i<n;i++){
            if(goal[i]) continue;
            bool ableall = true;
            for(int j=0;j<3;j++){
                bool ableany = false;
                for(int k=0;k<n;k++){
                    if(!goal[k]) continue;
                    if(goal[k] && cango[i][abc[j]][k]){
                        ableany = true;
                        break;
                    }
                }
                if(!ableany){
                    ableall = false;
                    break;
                }
            }
            if(ableall){
                if(i == 0){
                    cout << t << endl;
                    return 0;
                }
                goal_new[i] = true;
            }
        }
        goal = goal_new;
    }

    cout << "IMPOSSIBLE" << endl;
    return 0;
}