#include <bits/stdc++.h>
using namespace std;
int a[300030];
int p[300030];
set<pair<int, int> > v[300030];
unordered_map<int, int> mp[300030];
int n, m;
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 0; i < n; ++i) scanf("%d", a + i);
  for (int i = 0; i < n; ++i) p[a[i]] = i;
  for (int i = 0, x, y; i < m; ++i) {
    scanf("%d%d", &x, &y);
    v[y].insert(pair<int, int>(-p[x], x));
    mp[y][x] = 1;
  }
  int now = a[n - 1], np = n - 1;
  int ans = 0;
  for (auto c : v[now]) {
    int pos = -c.first;
    int id = c.second;
    auto it = v[id].begin();
    bool flag = 1;
    for (int i = pos + 1; flag && i < np; ++i)
      if (!mp[a[i]].count(id)) flag = 0;
    if (!flag) break;
    ans++;
    np = pos;
  }
  cout << ans << ('\n');
}
