#include <bits/stdc++.h>
using namespace std;
long long arr[1000000], h1[1000000], h2[1000000], in[1000000];
vector<long long> adj[1000000];
multiset<long long> st;
int main() {
  ios::sync_with_stdio(0);
  long long n, m;
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    cin >> arr[i];
    in[arr[i]] = i;
  }
  for (int i = 0; i < m; i++) {
    long long a, b;
    cin >> a >> b;
    adj[in[b]].push_back(in[a]);
  }
  for (int i = 0; i < adj[n - 1].size(); i++) {
    h1[adj[n - 1][i]] = 1;
  }
  bool flg = 0, flg2 = 0;
  long long cnt = 0, ans = 0;
  for (int i = n - 2; i >= 0; i--) {
    if (flg == 0) {
      if (h1[i] == 0) {
        flg = 1;
      } else {
        ans++;
      }
    }
    if (flg == 1) {
      if (h2[i] == cnt && h1[i] == 1) {
        ans++;
      } else {
        cnt++;
      }
      for (int j = 0; j < adj[i].size(); j++) {
        h2[adj[i][j]]++;
      }
    }
  }
  cout << ans;
}
