Example

Input

3 3 1 2 4
1 2
2 3
3 1


Output

IMPOSSIBLE
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cstdint>

using namespace std;
static const int INF = 1000000000;
static int dp[10000][50];

vector<uint64_t> matmul(
	const vector<uint64_t> &a, const vector<uint64_t> &b)
{
	const int n = a.size();
	vector<uint64_t> b_t(n);
	for(int i = 0; i < n; ++i){
		for(int j = 0; j < n; ++j){
			b_t[j] |= ((b[i] >> j) & 1) << i;
		}
	}
	vector<uint64_t> c(n);
	for(int i = 0; i < n; ++i){
		for(int j = 0; j < n; ++j){
			c[i] |= (a[i] & b_t[j]) ? (1ull << j) : 0ull;
		}
	}
	return c;
}

vector<uint64_t> matpow(const vector<uint64_t> &a, int p){
	const int n = a.size();
	vector<uint64_t> result(n);
	for(int i = 0; i < n; ++i){ result[i] = (1ull << i); }
	for(int i = 0; i < p; ++i){ result = matmul(result, a); }
	return result;
}

int main(){
	ios_base::sync_with_stdio(false);
	int n, m, a, b, c;
	cin >> n >> m >> a >> b >> c;
	vector<uint64_t> mat(n);
	for(int i = 0; i < m; ++i){
		int u, v;
		cin >> u >> v;
		--u; --v;
		mat[u] |= (1ull << v);
	}
	const auto a_mat = matpow(mat, a);
	const auto b_mat = matpow(mat, b);
	const auto c_mat = matpow(mat, c);
	for(int i = 0; i < 10000; ++i){
		for(int j = 0; j < n; ++j){ dp[i][j] = INF; }
		dp[i][n - 1] = 0;
	}
	for(int i = 9000; i >= 0; --i){
		for(int j = 0; j < n - 1; ++j){
			int as = INF, bs = INF, cs = INF;
			for(int k = 0; k < n; ++k){
				if(a_mat[j] & (1ull << k)){ as = min(as, dp[i + a][k]); }
				if(b_mat[j] & (1ull << k)){ bs = min(bs, dp[i + b][k]); }
				if(c_mat[j] & (1ull << k)){ cs = min(cs, dp[i + c][k]); }
			}
			dp[i][j] = max({ as, bs, cs }) + 1;
		}
	}
	const int answer = dp[0][0];
	if(answer >= INF){
		cout << "IMPOSSIBLE" << endl;
	}else{
		cout << answer << endl;
	}
	return 0;
}