#include <bits/stdc++.h>
#define ll long long
#define flt double
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
using namespace std;
const ll inf = 1e18;
mt19937 rnd(234);
const int maxn = 1e4;
const int maxln = 2e3;
ll base = 60;
ll mod = (1ll << base);
ll mask = mod - 1;
ll ln[maxn];
ll a[maxn][maxln];
void normalize_len(int i) {
while (ln[i] > 0 and a[i][ln[i] - 1] == 0) {
ln[i] -= 1;
}
}
void normalize(int i) {
;
ln[i] += 6;
for (int j = 0; j < ln[i]; j += 1) {
a[i][j + 1] += (a[i][j] >> base);
a[i][j] &= mask;
}
normalize_len(i);
}
void add(int i, int j) {
ln[j] = max(ln[i], ln[j]);
for (int k = 0; k < ln[j]; k += 1) {
a[j][k] += a[i][k];
}
}
ll logarithm(int i) {
normalize_len(i);
if (ln[i] == 0) {
return 0;
}
return base * (ln[i] - 1) + __lg(a[i][ln[i] - 1]);
}
int n, m;
vector<ll> x;
vector<vector<int>> g;
vector<int> usd;
vector<int> topsort, pos;
void dfs(int v) {
usd[v] = true;
for (auto to : g[v]) {
if (usd[to]) {
continue;
}
dfs(to);
}
pos[v] = n - (int)topsort.size() - 1;
topsort.push_back(v);
}
int32_t main() {
if (1) {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
}
cin >> n >> m;
x.resize(n);
for (int i = 0; i < n; i += 1) {
cin >> x[i];
}
g.assign(n, vector<int>());
for (int i = 0; i < m; i += 1) {
int u, v;;
cin >> u >> v;
--u;
--v;
g[u].push_back(v);
}
topsort.clear();
usd.assign(n, false);
pos.resize(n);
for (int v = 0; v < n; v += 1) {
if (usd[v]) {
continue;
}
dfs(v);
}
reverse(all(topsort));
for (int i = 0; i < n; i += 1) {
int v = topsort[i];
a[i][0] += x[v];
ln[i] = max(ln[i], 1ll);
add(i, i);
normalize(i);
int cnt = 0;
for (auto to : g[v]) {
int j = pos[to];
assert(i < j);
add(i, j);
cnt += 1;
if (cnt >= 8) {
normalize(j);
cnt = 0;
}
}
normalize(j);
}
cout << logarithm(n - 1) << "\n";
return 0;
}
/*
3 2
1 1 1
1 2
2 3
6 8
1 1 4 5 1 4
1 4
1 5
2 3
2 5
3 4
4 5
4 6
5 6
5 6
7 2 3 6 6
1 2
1 4
2 3
3 4
3 5
4 5
*/