#include <bits/stdc++.h>
using namespace std;
void solve() {
  map<pair<int, int>, int> mp;
  int n, m;
  cin >> n >> m;
  vector<int> v(n);
  for (int i = 0; i < n; i++) cin >> v[i];
  for (int i = 0; i < m; i++) {
    int x, y;
    cin >> x >> y;
    mp[{x, y}] = 1;
  }
  int i = n - 1;
  while (1) {
    if (i == 0) break;
    if (mp[{v[i - 1], v[i]}]) {
      swap(v[i - 1], v[i]);
      mp[{v[i - 1], v[i]}] = 0;
      i--;
    } else if (i > 1 && mp[{v[i - 2], v[i - 1]}]) {
      swap(v[i - 2], v[i - 1]);
      mp[{v[i - 2], v[i - 1]}] = 0;
    } else
      break;
  }
  cout << n - 1 - i << "\n";
}
int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0), cerr.tie(0);
  ;
  int t;
  t = 1;
  while (t--) {
    solve();
  }
  return 0;
}
