Example

Input

3 3 1 2 4
1 2
2 3
3 1


Output

IMPOSSIBLE
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
int r[60][60][110], dp[60][60], n, m, a[3]; vector<int>x[60];
void dfs(int st, int pos, int depth) {
	if (depth >= 102)return;
	if (r[st][pos][depth] == 1)return;
	r[st][pos][depth] = 1;
	for (int i : x[pos])dfs(st, i, depth + 1);
}
int solve(int pos, int depth) {
	if (depth >= 59)return 999999999;
	if (pos == n)return 0;
	if (dp[pos][depth] < (1 << 30))return dp[pos][depth];
	int maxn = 0;
	for (int i = 0; i < 3; i++) {
		int minx = 999999999;
		for (int j = 1; j <= n; j++) {
			if (r[pos][j][a[i]] == 1)minx = min(minx, solve(j, depth + 1) + 1);
		}
		maxn = max(maxn, minx);
	}
	dp[pos][depth] = maxn;
	return maxn;
}
int main() {
	cin >> n >> m >> a[0] >> a[1] >> a[2];
	for (int i = 0; i < 3600; i++)dp[i / 60][i % 60] = 2e9;
	for (int i = 0; i < m; i++) {
		int b, c; cin >> b >> c; x[b].push_back(c);
	}
	for (int i = 1; i <= n; i++)dfs(i, i, 0);
	int ret = solve(1, 0);
	if (ret >= 10000000)cout << "IMPOSSIBLE" << endl;
	else cout << ret << endl;
	return 0;
}