Example

Input

3 3 1 2 4
1 2
2 3
3 1


Output

IMPOSSIBLE
#include <queue>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#define N 55
#define M 2500
#define P 100
#define inf 0x3f3f3f3f
using namespace std;
struct Ahri
{
	int v,n;
}e[M];
int head[N],cnt;
inline void add(int u,int v)
{
	e[++cnt].v=v;
	e[cnt].n=head[u];
	head[u]=cnt;
}
bool f[P+5][N][N];
int dis[N],n,m,A,B,C;
int da[N],db[N],dc[N];
void getf() {
    for(int i = 1; i <= n; i++) f[0][i][i] = 1;

    for(int len = 0; len <= 101; len++) {
        for(int u = 1; u <= n; u++) {
            for(int v = 1; v <= n; v++) {
                if(f[len][u][v]) {
                    for(int p = head[v]; p; p = e[p].n) {
                        int w = e[p].v;
                        f[len + 1][u][w] = 1;
                    }
                }
            }
        }
    }

}
queue<int>q;
void bfs()
{
	while(!q.empty())q.pop();
	memset(dis,-1,sizeof dis);
	memset(da,0,sizeof da);
	memset(db,0,sizeof db);
	memset(dc,0,sizeof dc);
	
	int i,u;
	q.push(n),dis[n]=0;
	
	while(!q.empty())
	{
		u=q.front(),q.pop();

		for(i=1;i<=n;i++)if(dis[i]==-1)
		{
			if(!da[i]&&f[A][i][u])da[i]=dis[u]+1;
			if(!db[i]&&f[B][i][u])db[i]=dis[u]+1;
			if(!dc[i]&&f[C][i][u])dc[i]=dis[u]+1;
			if(da[i]&&db[i]&&dc[i])
				dis[i]=max(da[i],max(db[i],dc[i])),q.push(i);
		}
	}
}

int main()
{
//	freopen("test.in","r",stdin);
	int i,j,k;
	scanf("%d%d%d%d%d",&n,&m,&A,&B,&C);
	while(m--)
	{
		scanf("%d%d",&i,&j);
		add(i,j);
	}
	getf();
	bfs();
	if(dis[1]==-1)puts("IMPOSSIBLE");
	else printf("%d\n",dis[1]);
	
	return 0;
}