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=55;

bool  w[MAXN][MAXN],f[MAXN][MAXN][105];
int vis[MAXN];

int main()
{
    int n,m,len[3];
    scanf("%d%d",&n,&m);
    memset(w,0,sizeof(w));memset(f,0,sizeof(f));memset(vis,0,sizeof(vis));
    for (int i=0;i<3;i++) scanf("%d",&len[i]);
    for (int u,v;m--;)
    {
        scanf("%d%d",&u,&v);
        w[u][v]=true;
    }
    for (int i=1;i<=n;i++)
    {
        f[i][i][0]=true;
        for (int j=1;j<=100;j++)
            for (int k=1;k<=n;k++)
                for (int l=1;l<=n;l++)
                    if (w[l][k]&&f[i][l][j-1])
                        f[i][k][j]=true;
    }
    fill(vis+1,vis+n,INT_MAX);
    for (int now=1;now<=n;now++)
        for (int i=1;i<=n;i++)
            if (vis[i]>now)
            {
                bool flag;
                for (int j=0;j<3;j++)
                {
                    flag=false;
                    for (int k=1;k<=n;k++)
                        if (vis[k]<now&&f[i][k][len[j]])
                        {
                            flag=true;
                            break;
                        }
                    if (!flag) break;
                }
                if (flag)
                {
                    if (i==1)
                    {
                        printf("%d\n",now);
                        return 0;
                    }
                    vis[i]=now;
                }
            }
    puts("IMPOSSIBLE");
    return 0;
}