#include <bits/stdc++.h>
using namespace std;
vector<vector<int>> edges;
vector<int> group;
vector<int> core;
int dfs(int cur) {
  if (group[cur] != -1) return group[cur];
  int re = core[cur];
  int temp = 0;
  for (int i : edges[cur]) {
    int node = dfs(i);
    if (core[i] != core[cur]) {
      node += re;
    }
    temp = max(temp, node);
  }
  return group[cur] = max(re, temp);
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  edges.resize(n);
  group.resize(n, -1);
  core.resize(n);
  for (auto& it : core) {
    cin >> it;
  }
  for (int i = 0; i < m; i++) {
    int one, two;
    cin >> one >> two;
    edges[one].push_back(two);
  }
  int re = 0;
  int g = 0;
  for (int i = 0; i < n; i++) {
    re = max(re, dfs(i));
  }
  cout << re;
}
