#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 5;
int n, m;
int p[3 * maxn];
vector<int> G[5 * maxn];
int num[3 * maxn];
int vis[3 * maxn];
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &p[i]);
  }
  int u, v;
  for (int i = 1; i <= m; i++) {
    scanf("%d%d", &u, &v);
    G[v].push_back(u);
  }
  for (int i = 0; i < G[p[n]].size(); i++) {
    num[G[p[n]][i]] = 1;
  }
  int t;
  for (int i = 2; i <= n - 1; i++) {
    if (num[p[i - 1]]) {
      for (int j = 0; j < G[p[i]].size(); j++) {
        if (G[p[i]][j] == p[i - 1]) {
          t = p[i - 1];
          p[i - 1] = p[i];
          p[i] = t;
          break;
        }
      }
    }
  }
  int res = 0;
  t = n - 1;
  while (t >= 1 && num[p[t]]) t--, res++;
  printf("%d\n", res);
  return 0;
}
