#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
inline void smax(int &x, int y) { x = max(x, y); }
inline void smin(int &x, int y) { x = min(x, y); }
ll gcd(ll a, ll b) { return ((b == 0) ? a : gcd(b, a % b)); }
int main() {
  std::ios::sync_with_stdio(false);
  cin.tie(NULL);
  int n, m;
  cin >> n >> m;
  vector<int> v(n);
  for (__typeof(n) i = (0) - ((0) > (n)); i != (n) - ((0) > (n));
       i += 1 - 2 * ((0) > (n))) {
    cin >> v[i];
  }
  vector<vector<int> > sw(n + 1);
  for (__typeof(m) i = (0) - ((0) > (m)); i != (m) - ((0) > (m));
       i += 1 - 2 * ((0) > (m))) {
    int x, y;
    cin >> x >> y;
    sw[x].push_back(y);
  }
  int cnt = 0;
  vector<int> pre(n + 1);
  for (__typeof(n - 1) i = (0) - ((0) > (n - 1));
       i != (n - 1) - ((0) > (n - 1)); i += 1 - 2 * ((0) > (n - 1))) {
    int ah = 0;
    for (int j = 0; j < sw[v[i]].size(); j++) {
      if (!pre[sw[v[i]][j]]) ah++;
    }
    if (ah == n - i - 1) cnt++;
    pre[v[i]]++;
  }
  cout << cnt << endl;
}
