#include <bits/stdc++.h>
using namespace std;
const int maxn = 3 * 100000 + 100;
const int M = 2000;
const int maxm = 500000 + 100;
const int INF = 0x3f3f3f3f;
const long long mod = 1000000007;
const double eps = 1e-8;
int n, m;
int que[maxn];
set<pair<int, int> > sset;
bool vis[maxn];
int main() {
  cin >> n >> m;
  memset(vis, false, sizeof(vis));
  for (int i = 1; i <= n; i++) {
    scanf("%d", &que[i]);
  }
  int u, v;
  for (int i = 0; i < m; i++) {
    scanf("%d%d", &u, &v);
    sset.insert(make_pair(u, v));
  }
  int pos = n, cur = n;
  while (1 < pos) {
    bool ok = false;
    int i;
    for (i = pos - 1; i >= 1; i--) {
      if (sset.count(make_pair(que[i], que[pos]))) {
        ok = true;
        break;
      }
    }
    if (ok) {
      bool flag = true;
      for (int j = i + 1; j < pos; j++) {
        if (sset.count(make_pair(que[i], que[j])))
          continue;
        else {
          flag = false;
          break;
        }
      }
      if (flag) {
        for (int j = i; j < pos; j++) {
          swap(que[j], que[j + 1]);
        }
        pos--;
      } else {
        break;
      }
    } else {
      break;
    }
  }
  printf("%d\n", n - pos);
  return 0;
}
