Example

Input

3 3 1 2 4
1 2
2 3
3 1


Output

IMPOSSIBLE
#include <vector>
#include <iostream>
using namespace std;
int n, m, x[3], a, b, dist[55]; vector<int> G[55]; bool dp[55][55][109];
int main() {
	cin >> n >> m;
	for (int i = 0; i < 3; i++) cin >> x[i];
	for (int i = 0; i < m; i++) {
		cin >> a >> b; a--, b--;
		G[a].push_back(b);
	}
	for (int i = 0; i < n; i++) {
		dp[i][i][0] = true;
		for (int j = 0; j < 100; j++) {
			for (int k = 0; k < n; k++) {
				if (dp[i][k][j]) {
					for (int l : G[k]) dp[i][l][j + 1] = true;
				}
			}
		}
	}
	fill(dist, dist + n - 1, 999999999);
	for (int i = 0; i < 100; i++) {
		for (int j = 0; j < n; j++) {
			if (dist[j] != 999999999) continue;
			int cnt = 0;
			for (int k = 0; k < 3; k++) {
				for (int l = 0; l < n; l++) {
					if (dp[j][l][x[k]] && dist[l] <= i) {
						cnt++; break;
					}
				}
			}
			if (cnt == 3) dist[j] = i + 1;
		}
	}
	if (dist[0] == 999999999) cout << "IMPOSSIBLE" << endl;
	else cout << dist[0] << endl;
	return 0;
}