#include <bits/stdc++.h>
using namespace std;
int n, m, ans;
int p[300010];
bool el[300010], test;
pair<int, int> a[500010];
bool pos(int t1, int t2) {
  int st = 1, dr = m, mij;
  while (st < dr) {
    mij = (st + dr) / 2;
    if (make_pair(t1, t2) <= a[mij])
      dr = mij;
    else
      st = mij + 1;
  }
  return (a[st] == make_pair(t1, t2));
}
int main() {
  cin >> n >> m;
  for (int i = 1; i <= n; i++) cin >> p[i];
  for (int i = 1; i <= m; i++) cin >> a[i].first >> a[i].second;
  for (int i = n - 1; i >= 1; i--) {
    if (pos(p[i], p[n])) {
      test = 1;
      for (int j = i + 1; j <= n; j++)
        if (!(el[j] || pos(p[i], p[j]))) {
          test = 0;
          break;
        }
      if (test) {
        el[i] = 1;
        ans++;
      }
    }
  }
  cout << ans;
  return 0;
}
