#include <bits/stdc++.h>
using namespace std;
int n, e[100010];
vector<bool> vis(100010, false);
vector<int> a[100010], leafs, sol;
void dfs(int c = 0, int p = -1) {
  vis[c] = true;
  for (int i = 0; i < a[c].size(); ++i) {
    if (a[c][i] == p) continue;
    if (vis[a[c][i]] == false) dfs(a[c][i], c);
  }
  if (a[c].size() == 0) leafs.push_back(c);
}
int solve(int p = 0) {
  if (sol[p] != -1) return sol[p];
  if (e[p] == 1)
    for (int i = 0; i < a[p].size(); ++i)
      sol[p] = max(sol[p], solve(a[p][i]) + 1 - e[a[p][i]]);
  else
    for (int i = 0; i < a[p].size(); ++i) sol[p] = max(sol[p], solve(a[p][i]));
  return sol[p];
}
int main() {
  int m, ans = 0;
  scanf("%i%i", &n, &m);
  for (int i = 0; i < n; ++i) scanf("%i", &e[i]);
  for (int i = 0, t1, t2; i < m; ++i) {
    scanf("%i%i", &t1, &t2);
    a[t1].push_back(t2);
  }
  for (int i = 0; i < n; ++i)
    if (vis[i] == false) dfs(i);
  sol.resize(n, -1);
  for (int i = 0; i < leafs.size(); ++i) sol[leafs[i]] = e[leafs[i]];
  for (int i = 0; i < n; ++i)
    if (sol[i] == -1) solve(i);
  for (auto it : sol) ans = max(ans, it);
  printf("%i", ans);
  return 0;
}
