#include <bits/stdc++.h>
using namespace std;
int in() {
  int n;
  scanf("%d", &n);
  return n;
}
class Graph {
  int V;
  list<int> *adj;
  void topologicalSortUtil(int v, bool visited[], stack<int> &Stack);

 public:
  Graph(int V);
  void addEdge(int v, int w);
  stack<int> topologicalSort();
};
Graph::Graph(int V) {
  this->V = V;
  adj = new list<int>[V + 1];
}
void Graph::addEdge(int v, int w) { adj[v].push_back(w); }
void Graph::topologicalSortUtil(int v, bool visited[], stack<int> &Stack) {
  visited[v] = true;
  list<int>::iterator i;
  for (i = adj[v].begin(); i != adj[v].end(); ++i)
    if (!visited[*i]) topologicalSortUtil(*i, visited, Stack);
  Stack.push(v);
}
stack<int> Graph::topologicalSort() {
  stack<int> Stack;
  bool *visited = new bool[V];
  for (int i = 0; i < V; i++) visited[i] = false;
  for (int i = 0; i < V; i++)
    if (visited[i] == false) topologicalSortUtil(i, visited, Stack);
  return Stack;
}
int main() {
  int n = in();
  int m = in();
  Graph g(n);
  vector<int> v(n);
  for (int i = 0; i < n; i++) cin >> v[i];
  set<int> s;
  for (int i = 0; i < m; i++) {
    int a = in();
    int b = in();
    if (b == v[n - 1]) s.insert(a);
    g.addEdge(b, a);
  }
  stack<int> Stack = g.topologicalSort();
  int count = 0;
  while (!Stack.empty()) {
    int top = Stack.top();
    Stack.pop();
    if (top == v[n - 1]) count = 0;
    if (s.find(top) != s.end()) count++;
  }
  cout << count << '\n';
}
