#include <bits/stdc++.h>
using namespace std;
int a[100007], dp[100007];
vector<int> edge[100007];
int solve(int x) {
  if (dp[x] != -1) {
    return dp[x];
  }
  dp[x] = 0;
  for (int y : edge[x]) {
    int cost;
    if (a[x] == 0) {
      cost = 0;
    } else {
      if (a[y] != a[x]) {
        cost = 1;
      } else {
        cost = 0;
      }
    }
    dp[x] = max(dp[x], solve(y) + cost);
  }
  dp[x] = max(dp[x], a[x]);
  return dp[x];
}
int main() {
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  while (m--) {
    int u, v;
    cin >> u >> v;
    edge[u].push_back(v);
  }
  memset(dp, -1, sizeof(dp));
  int ans = 0;
  for (int i = 0; i < n; i++) {
    ans = max(ans, solve(i));
  }
  cout << ans;
}
