Example

Input

3 3 1 2 4
1 2
2 3
3 1


Output

IMPOSSIBLE
#include <bits/stdc++.h>

using namespace std;

const int inf = 0x3f3f3f3f;

struct Node {
	int d, x;
	Node(int _x = 0, int _d = 0):d(_d), x(_x) {}
};

int n, m, X[5], u, v;
int S[5][60][60];
int dis[60];
vector <int> G[60];
queue <Node> Q;
bool vis[60][200];

void BFS(int u) {
	memset(vis, 0, sizeof(vis));
	while(!Q.empty()) Q.pop();
	Q.push(Node(u, 0)); vis[u][0] = 1;
	while(!Q.empty()) {
		int x = Q.front().x, d = Q.front().d; Q.pop();
		for(int i = 0; i < 3; i ++) if(d == X[i]) {
			S[i][x][u] = 1;
		}
		if(d == X[2]) continue;
		for(unsigned i = 0; i < G[x].size(); i ++) {
			int y = G[x][i];
			if(!vis[y][d+1]) {
				Q.push(Node(y, d+1));
				vis[y][d+1] = 1;
			}
		}
	}
}

int main() {
	//freopen("C.in", "r", stdin);
	scanf("%d%d%d%d%d", &n, &m, &X[0], &X[1], &X[2]);
	sort(X, X+3);
	for(int i = 0; i < m; i ++) {
		scanf("%d%d", &u, &v);
		G[v].push_back(u);
	}
	memset(S, 0, sizeof(S));
	for(int i = 1; i <= n; i ++) BFS(i);
	
	memset(dis, 0x3f, sizeof(dis));
	dis[n] = 0;
	for(int p = 1; p <= 2*n; p ++) {
		for(int i = 1; i <= n; i ++) {
			int Mx = 0;
			for(int k = 0; k < 3; k ++) {
				int Mn = inf;
				for(int j = 1; j <= n; j ++) if(S[k][i][j]) {
					Mn = min(Mn, dis[j]);
				}
				Mx = max(Mx, Mn);
			}
			dis[i] = min(dis[i], Mx+1);
		}
	}
	
	if(dis[1] == inf) printf("IMPOSSIBLE\n");
	else printf("%d\n", dis[1]);
	return 0;
}