Example

Input

3 3 1 2 4
1 2
2 3
3 1


Output

IMPOSSIBLE
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <memory.h>
#include <math.h>
#include <assert.h>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <string>
#include <algorithm>
#include <iostream>
#include <functional>

using namespace std;
typedef long long ll;
typedef pair<int, int> Pi;
#define Fi first
#define Se second
#define pb(x) push_back(x)
#define sz(x) (int)x.size()
#define rep(i,n) for(int i=0;i<n;i++)
#define all(x) x.begin(),x.end()

vector <int> E[55];
int n, m, a[3], ans[55][4];
ll d[52][102];

void solve(int tc){
	scanf("%d%d%d%d%d", &n, &m, a, a+1, a+2);
	for(int i=0;i<m;i++){
		int x, y;
		scanf("%d%d", &x, &y);
		E[x].pb(y);
	}
	for(int i=1;i<=n;i++){
		d[i][0] = 1LL<<i;
		for(int j=1;j<=100;j++){
			for(int k=1;k<=n;k++){
				if(d[i][j-1] & 1LL<<k){
					for(auto u : E[k]){
						d[i][j] |= 1LL<<u;
					}
				}
			}
		}
	}
	for(int i=1;i<=n;i++)for(int j=0;j<4;j++)ans[i][j] = 101;
	for(int i=0;i<4;i++)ans[n][i] = 0;
	for(int i=1;i<=n;i++){
		for(int j=1;j<=n;j++){
			ans[j][3] = max(max(ans[j][0], ans[j][1]), ans[j][2]);
			if(ans[j][3] != 101){
				for(int k=1;k<=n;k++){
					rep(u, 3){
						if(d[k][a[u]] & 1LL<<j){
							ans[k][u] = min(ans[k][u], ans[j][3] + 1);
						}
					}
				}
			}
		}
	}
	if(ans[1][3] != 101)printf("%d\n", ans[1][3]);
	else printf("IMPOSSIBLE\n");
}

int main(){
	int Tc = 1;// scanf("%d",&Tc);
	for(int i=1;i<=Tc;i++){
		solve(i);
	}
	return 0;
}