#include <bits/stdc++.h>
using namespace std;
const int N = 500005;
vector<int> lis[N];
vector<int> rlis[N];
int good[N];
int mark[N];
int ar[N];
int rev[N];
priority_queue<pair<int, int> > pq;
int main() {
  int n, m;
  scanf("%d %d", &n, &m);
  for (int i = 0; i < n; i++) {
    scanf("%d", &ar[i]);
    rev[ar[i]] = i;
  }
  int kaguya = ar[n - 1];
  for (int i = 0; i < m; i++) {
    int a, b;
    scanf("%d %d", &a, &b);
    if (b == kaguya) good[a] = 1;
    lis[b].push_back(a);
  }
  for (int i = 0; i < n - 1; i++) {
    if (good[ar[i]]) continue;
    for (int j = 0; j < lis[ar[i]].size(); j++) {
      if (rev[lis[ar[i]][j]] > i) continue;
      pq.push(pair<int, int>(rev[lis[ar[i]][j]], lis[ar[i]][j]));
    }
    int x = i;
    while (!pq.empty() && x > 0) {
      if (pq.top().second == ar[x - 1]) {
        swap(rev[ar[x]], rev[pq.top().second]);
        swap(ar[x], ar[pq.top().first]);
        x = x - 1;
      }
      pq.pop();
    }
    while (!pq.empty()) pq.pop();
  }
  int ans = 0;
  for (int i = n - 2; i >= 0; i--) {
    if (good[ar[i]])
      ans++;
    else
      break;
  }
  printf("%d\n", ans);
  return 0;
}
