#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 55;
vector<int> vec[N];
int E[N];
int dp[N];
int n, m;
int dfs(int u) {
  if (dp[u] != -1) return dp[u];
  int curr = 0;
  for (auto v : vec[u]) {
    if (E[v])
      curr = max(curr, dfs(v));
    else
      curr = max(curr, dfs(v) + E[u]);
  }
  dp[u] = curr;
  if (vec[u].size() == 0) dp[u] += E[u];
  return dp[u];
}
int main() {
  ios::sync_with_stdio(false);
  memset(dp, -1, sizeof(dp));
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    cin >> E[i];
  }
  int u, v;
  for (int i = 0; i < m; i++) {
    cin >> u >> v;
    vec[u].push_back(v);
  }
  int ans = 0;
  for (int i = 0; i < n; i++) {
    ans = max(ans, dfs(i));
  }
  cout << ans << endl;
  return 0;
}
