#include <bits/stdc++.h>
using namespace std;
const int maxn = 3e5 + 5;
int a[maxn], tag[maxn], vis[maxn];
vector<int> v[maxn];
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
  for (int i = 1; i <= m; i++) {
    int x, y;
    scanf("%d%d", &x, &y);
    if (y == a[n])
      tag[x] = 1;
    else
      v[y].push_back(x);
  }
  int ans = 0, cnt = 0;
  for (int i = n - 1; i >= 1; i--) {
    if (tag[a[i]]) {
      if (vis[a[i]] == cnt) ans++;
    } else {
      for (int x : v[a[i]]) vis[x]++;
      cnt++;
    }
  }
  printf("%d\n", ans);
  return 0;
}
