Example

Input

3 3 1 2 4
1 2
2 3
3 1


Output

IMPOSSIBLE
#include<bits/stdc++.h>
using namespace std;
const int maxn=53;
int n,m,A,B,C; bool e[maxn][maxn];
void init(){
    scanf("%d%d%d%d%d",&n,&m,&A,&B,&C); memset(e,0,sizeof(e));
    for (int i=1,a,b;i<=m;++i){
        scanf("%d%d",&a,&b); e[a][b]=1;
    }
}
bool Can[maxn][maxn];
struct Tmx{
    bool a[maxn][maxn];
	void clear(){memset(a,0,sizeof(a));}
};
Tmx operator *(Tmx a,Tmx b){
    Tmx c; c.clear();
    for (int k=1;k<=n;++k) for (int i=1;i<=n;++i) for (int j=1;j<=n;++j) c.a[i][j]|=a.a[i][k]&b.a[k][j];
    return c;
}
void work(){
    Tmx a; memcpy(a.a,e,sizeof(e));

    Tmx tmp1=a;
    for (int i=1;i<A;++i) tmp1=tmp1*a;

	Tmx tmp2=a;
    for (int i=1;i<B;++i) tmp2=tmp2*a;

	Tmx tmp3=a;
    for (int i=1;i<C;++i) tmp3=tmp3*a;

    static int ans[maxn]; memset(ans,63,sizeof(ans));
	ans[n]=0;
	for (int i=1;i<=n;++i){
		for (int j=1;j<=n;++j){
            int res1=-1,res2=ans[0];
			for (int k=1;k<=n;++k) if (tmp1.a[j][k]) res2=min(res2,ans[k]+1);
			res1=res2; res2=ans[0];
			for (int k=1;k<=n;++k) if (tmp2.a[j][k]) res2=min(res2,ans[k]+1);
			res1=max(res1,res2); res2=ans[0];
			for (int k=1;k<=n;++k) if (tmp3.a[j][k]) res2=min(res2,ans[k]+1);
			res1=max(res1,res2);
			if (res1<ans[j]) ans[j]=res1;
		}
	}
	if (ans[1]<=n) printf("%d\n",ans[1]);else puts("IMPOSSIBLE");
}
int main(){
    init();
    work();
    return 0;
}