Example

Input

3 3 1 2 4
1 2
2 3
3 1


Output

IMPOSSIBLE
#include <algorithm>
#include <functional>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <bitset>
#include <climits>

#define all(c) (c).begin(), (c).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define pb(e) push_back(e)
#define mp(a, b) make_pair(a, b)
#define fr first
#define sc second

const int INF=100000000;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
using namespace std;
typedef pair<int ,int > P;
typedef long long ll;
typedef vector<int> Vec;
typedef vector<Vec> Mat;

Mat mul(Mat &A, Mat &B) {
    Mat C(A.size(),Vec(B[0].size()));
    rep(i,A.size()) rep(k,B.size()) rep(j,B[0].size()) {
        C[i][j]+=A[i][k]*B[k][j];
        if(C[i][j]) C[i][j]=1;
    }

    return C;
}

Mat pow(Mat A, int n) {
    Mat B(A.size(), Vec(A.size()));
    rep(i,A.size()) B[i][i]=1;
    while(n) {
        if(n&1) B=mul(B,A);
        A=mul(A,A);
        n>>=1;
    }
    return B;
}

vector<int> G[52];
int n,m;
int a,b,c;
int steps[3];
Mat mat[3];
int d[52];
int goal;

bool ok(int v,int u) {
    bool f=true;
    rep(i,3) f&=mat[i][v][u]!=0;
    return f;
}

int nextCost(int u) {
    int ret=-1;
    rep(i,3) {
        int t=INF;
        rep(v,n) {
            if(mat[i][v][u]>0) {
                t=min(t,d[v]);
            }
        }

        ret=max(ret,t);
    }

    return ret;
}

void bfs() {
    d[goal]=0;
    bool f=true;
    while(f) {
        f=false;
        //printf("debug %d %d\n",v,d[v]);
        rep(u,n) {
            int t=nextCost(u);
            if(t==-1||t==INF) continue;
            if(d[u]>t+1) {
                f=true;
                d[u]=t+1;
            }
        }
    }
}

int main() {
    rep(i,52) d[i]=INF;
    cin>>n>>m;
    cin>>a>>b>>c;
    steps[0]=a; steps[1]=b; steps[2]=c;
    goal = n-1;
    rep(i,3) mat[i]=Mat(52,Vec(52));
    rep(i,m) {
        int s,t;
        cin>>s>>t; s--;t--;
        G[t].pb(s);
        rep(i,3) mat[i][t][s]=1;
    }
    rep(i,3) mat[i]=pow(mat[i],steps[i]);
    bfs();
    int ans=d[0];

    if(ans==INF) cout<<"IMPOSSIBLE"<<endl;
    else cout<<ans<<endl;
    return 0;
}