#include <bits/stdc++.h>
using namespace std;
const long long N = 4e5;
long long a[N], b[N], c[N], first, second;
vector<long long> ke[N];
long long dfs(long long u, long long p) {
  if (c[u]) return c[u];
  c[u] = a[u];
  for (auto& v : ke[u])
    if (v != p) c[u] = max(c[u], dfs(v, p) + (!a[v] && a[u]));
  return c[u];
}
int main() {
  long long n, m;
  cin >> n >> m;
  for (long long i = (long long)1; i <= (long long)n; i++) cin >> a[i];
  for (long long i = (long long)1; i <= (long long)m; i++) {
    cin >> first >> second;
    first++;
    second++;
    ke[first].push_back(second);
    b[second] = 1;
  }
  for (long long i = (long long)1; i <= (long long)n; i++)
    if (!b[i]) dfs(i, i);
  cout << *max_element(c + 1, c + 1 + n) << " ";
}
