#include <bits/stdc++.h>
using namespace std;
int n, m, p[300005], q[300005], first, second, t[300005], k;
int32_t main() {
  ios_base ::sync_with_stdio(0);
  cin.tie();
  cout.tie();
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    cin >> p[i];
    q[p[i]] = i;
  }
  for (int i = 1; i <= m; i++) {
    cin >> first >> second;
    if (q[first] < q[second]) t[q[first]]++;
  }
  for (int i = n - 1; i >= 1; i--) {
    if (t[i] >= n - i - k) k++;
  }
  cout << k;
}
