#include <bits/stdc++.h>
using namespace std;
int xx[4] = {1, -1, 0, 0};
int yy[4] = {0, 0, 1, -1};
const double eps = 1e-9;
const int maxn = 2e6 + 200;
const long long mod = 1e9 + 7;
inline int sign(double a) { return a < -eps ? -1 : a > eps; }
long long mul(long long a, long long b, long long c) {
  long long res = 1;
  while (b) {
    if (b & 1) res *= a, res %= c;
    a *= a, a %= c, b >>= 1;
  }
  return res;
}
long long phi(long long x) {
  long long res = x;
  for (long long i = 2; i * i <= x; i++) {
    if (x % i == 0) res = res / i * (i - 1);
    while (x % i == 0) x /= i;
  }
  if (x > 1) res = res / x * (x - 1);
  return res;
}
int fa[maxn];
int Find(int x) {
  if (x != fa[x]) return fa[x] = Find(fa[x]);
  return fa[x];
}
long long c, n, k;
long long a[maxn];
int vis[maxn];
int cnt[maxn];
int mm;
struct node {
  int a, b;
} g[maxn];
map<pair<int, int>, int> m;
int ans = 0;
int check(int d) { return n - d - ans <= cnt[a[d]]; }
vector<int> v;
int main() {
  ios::sync_with_stdio(false);
  while (cin >> n >> mm) {
    for (int i = 1; i <= n; i++) {
      cin >> a[i];
      vis[a[i]] = i;
    }
    for (int i = 1; i <= mm; i++) {
      cin >> g[i].a >> g[i].b;
      if (vis[g[i].a] < vis[g[i].b]) cnt[g[i].a]++;
      if (g[i].b == a[n]) v.push_back(vis[g[i].a]);
    }
    sort(v.begin(), v.end());
    for (auto d : v) {
      ans += check(d);
    }
    cout << ans << endl;
  }
  cerr << "time: " << (long long)clock() * 1000 / CLOCKS_PER_SEC << " ms"
       << endl;
  return 0;
}
