Example

Input

3 3 1 2 4
1 2
2 3
3 1


Output

IMPOSSIBLE
#include <bits/stdc++.h>
using namespace std;

int n, m, a, b, c;
int can[50][50][110];
vector<int> G[50];

void bfs(int s) {
	can[s][s][0] = 1;
	for (int t = 0; t < 100; t++) {
		for (int v = 0; v < n; v++) {
			if (can[s][v][t] == 0)
				continue;
			for (int u : G[v]) {
				can[s][u][t + 1] = 1;
			}
		}
	}
}

const int MAX_T = 5010;
const int INF = 1 << 25;
int dp[MAX_T][50];

int f(int t, int v) {
	if (v == n - 1)
		return 0;
	if (t == MAX_T)
		return INF;

	int& d = dp[t][v];
	if (d != -1)
		return d;

	int m[3] = { a, b, c };
	d = 0;
	for (int i = 0; i < 3; i++) { // opp
		int mindist = INF;
		for (int u = 0; u < n; u++) { // my
			if (can[v][u][m[i]]) {
				mindist = min(mindist, f(t + 1, u) + 1);
			}
		}
		d = max(d, mindist);
	}
	return d;
}

int main() {
	cin >> n >> m >> a >> b >> c;

	for (int i = 0; i < m; ++i) {
		int u, v;
		cin >> u >> v;
		u--, v--;
		G[u].push_back(v);
	}

	for (int i = 0; i < n; ++i) {
		bfs(i);
	}

	memset(dp, -1, sizeof dp);
	int res = f(0, 0);
	if (res == INF)
		cout << "IMPOSSIBLE" << endl;
	else
		cout << res << endl;
}