#include <bits/stdc++.h>
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
long long n, m, res = 0;
vector<long long> pos, mas, rad;
vector<vector<long long>> cons;
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m;
  mas.resize(n);
  pos.resize(n);
  rad.resize(n);
  cons.resize(n);
  for (long long i = 0; i < n; i++) {
    cin >> mas[i];
    mas[i]--;
    pos[mas[i]] = i;
  }
  for (long long i = 0; i < m; i++) {
    long long a, b;
    cin >> a >> b;
    a--;
    b--;
    if (pos[b] < pos[a]) continue;
    cons[pos[a]].push_back(pos[b] - pos[a]);
  }
  for (long long i = 0; i < n; i++) {
    sort(cons[i].begin(), cons[i].end());
    long long l = 0, r = cons[i].size() + 1;
    while (r - l > 1) {
      long long mid = (r + l) / 2;
      if (cons[i][mid - 1] == mid) {
        l = mid;
      } else {
        r = mid;
      }
    }
    rad[i] = l;
  }
  for (long long i = 0; i < n - 1; i++) {
    if (rad[i] == n - i - 1) res++;
  }
  cout << res;
  return 0;
}
