#include <bits/stdc++.h>
using namespace std;
int p[300010];
struct node {
  int k;
} a[500010];
int main() {
  int n, m, x, y, i, j = 0, ans = 0;
  cin >> n >> m;
  for (i = 1; i <= n; i++) {
    cin >> p[i];
    a[p[i]].k = i;
  }
  for (i = 0; i < m; i++) {
    cin >> x >> y;
    if (a[x].k >= j && i != 0) continue;
    if (a[x].k < a[y].k) {
      ans++;
      j = a[x].k;
    }
  }
  cout << ans << endl;
  return 0;
}
