#include <bits/stdc++.h>
using namespace std;
const long long N = 6e5;
long long n, m, s, so, cur;
long long p[N], a[N];
vector<long long> v, q[N];
bool cmp(long long first, long long second) { return p[first] > p[second]; }
int main() {
  cin >> n >> m;
  for (long long i = (long long)1; i <= (long long)n; i++) {
    long long t;
    cin >> t;
    p[t] = i;
    a[i] = t;
  }
  for (long long i = (long long)1; i <= (long long)m; i++) {
    long long first, second;
    cin >> first >> second;
    q[first].push_back(second);
    if (second == a[n]) v.push_back(first);
  }
  sort((v).begin(), (v).end(), cmp);
  cur = n;
  for (auto& i : v) {
    s = 0;
    for (__typeof((q[i]).begin()) k = (q[i]).begin(); k != (q[i]).end(); k++)
      if (p[*k] > p[i] && p[*k] < cur) s++;
    if (s >= cur - p[i] - 1) so++, cur = p[i];
  }
  cout << so << "\n";
}
