#include <bits/stdc++.h>
using namespace std;
bool isVowel(char c) {
  return c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u';
}
bool isLower(char c) { return 97 <= c && c <= 122; }
bool prime[1001];
void sieve() {
  fill(prime, prime + 1000, 1);
  prime[0] = prime[1] = 0;
  for (long long int i = 2; i < 1000; i += 1) {
    if (prime[i]) {
      for (long long int j = i * 2; j < 1000; j += i) prime[j] = 0;
    }
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long int n, m;
  cin >> n >> m;
  long long int a[n];
  unordered_map<long long int, long long int> ind;
  for (long long int i = 0; i < n; i++) {
    cin >> a[i];
    ind[a[i]] = i;
  }
  long long int p = a[n - 1];
  vector<long long int> b;
  map<long long int, unordered_map<long long int, long long int>> fr, bc;
  long long int u, v;
  for (long long int i = 0; i < m; i++) {
    cin >> u >> v;
    fr[u][v] = 1;
    bc[v][u] = 1;
    if (v == p) {
      b.push_back(u);
    }
  }
  unordered_map<long long int, long long int> final;
  final[n - 1] = 1;
  long long int i;
  for (long long int e : b) {
    i = ind[e];
    while (i >= 0 && i - 1 >= 0 && fr[e][a[i - 1]]) {
      final[i] = 1;
      i--;
    }
    i = ind[e];
    while (i < n && i + 1 < n && fr[e][a[i + 1]]) {
      final[i] = 1;
      i++;
    }
  }
  long long int tot = b.size() + 1;
  long long int ans = n - 1;
  while (final[ans] && tot) {
    ans--;
    tot--;
  }
  cout << n - 2 - ans;
}
