#include <bits/stdc++.h>
using namespace std;
template <typename T>
inline void Cin(T& x) {
  char c;
  T sign = 1;
  x = 0;
  for (c = getchar(); c < '0' || c > '9'; c = getchar())
    if (c == '-') sign = -1;
  for (; c >= '0' && c <= '9'; c = getchar()) x = x * 10 + c - '0';
  x *= sign;
}
template <typename T>
inline void Out(T x) {
  if (x > 9) Out(x / 10);
  putchar(x % 10 + '0');
}
template <typename T>
inline void Cout(T x, char c) {
  if (x < 0) putchar('-');
  x = abs(x);
  Out(x);
  putchar(c);
}
template <typename T, typename... Args>
inline void Cin(T& a, Args&... args) {
  Cin(a);
  Cin(args...);
}
template <typename T, typename... Args>
inline void Cout(T a, char c, Args... args) {
  Cout(a, c);
  Cout(args...);
}
const int N = 1e6 + 7;
int n, m, u, v, p[N];
vector<int> a[N];
set<int> s1, s2;
void Enter() {
  Cin(n, m);
  for (int i = 1; i <= n; ++i) Cin(p[i]);
  for (int i = 1; i <= m; ++i) {
    Cin(u, v);
    a[v].emplace_back(u);
  }
  s1.insert(p[1]);
  for (int i = 2; i <= n; ++i) {
    s2.clear();
    for (int v : a[p[i]])
      if (s1.find(v) != s1.end()) s2.insert(v);
    s1 = s2;
    s1.insert(p[i]);
  }
  cout << int(s1.size()) - 1;
}
void Solve() {}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  Enter();
  Solve();
  return 0;
}
