#include <bits/stdc++.h>
using namespace std;
const int N = 5e5 + 5;
long long n, m, k, x, y, a, b, t, p, ans, sum;
string s;
vector<long long> gr[N], v;
long long A[N], B[505][505], tree[N * 4], fix[N], F[N], G[N];
map<pair<long long, long long>, int> mp;
int main() {
  ios::sync_with_stdio(0);
  cin >> n >> m;
  for (int i = 1; i <= n; i++) cin >> A[i];
  for (int i = 0; i < m; i++) {
    cin >> x >> y;
    mp[{x, y}] = 1;
  }
  int ind = n - 1;
  while (fix[A[ind]] == 0 && ind > 0) {
    fix[A[ind]] = 1;
    if (mp[{A[ind], A[n]}] == 1)
      ind--;
    else {
      k = ind;
      while (mp[{A[k - 1], A[k]}] == 1) swap(A[k - 1], A[k]);
    }
  }
  cout << n - ind - 1 << endl;
}
