#include <bits/stdc++.h>
using namespace std;
int q[1005];
int n, m;
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; ++i) {
    scanf("%d", &q[i]);
  }
  int idx = 0;
  int f = 0;
  int s = 0;
  vector<int> adj[1005];
  while (idx < m) {
    scanf("%d%d", &f, &s);
    adj[f].push_back(s);
    adj[s].push_back(f);
    idx++;
  }
  int ans = 0;
  for (int i = n; i >= 2; --i) {
    bool visit = false;
    for (auto j : adj[i]) {
      if (j == q[i - 1]) {
        visit = true;
        break;
      }
    }
    if (visit) {
      ans++;
    } else {
      break;
    }
  }
  cout << ans;
  return 0;
}
