#include <bits/stdc++.h>
using namespace std;
const double pi = acos(-1.0);
const double eps = 1e-8;
const int MOD = 1e9 + 7;
const int INF = 0x3f3f3f3f;
const int maxn = 5e5 + 10;
const int maxm = 2e5 + 10;
int n, m;
vector<int> e[maxn];
int arr[maxn], d[maxn], vis[maxn];
map<pair<int, int>, int> mp;
int main() {
  cin >> n >> m;
  for (int i = 1; i <= n; ++i) cin >> arr[i], d[arr[i]] = i;
  for (int i = 1, a, b; i <= m; ++i) {
    cin >> a >> b;
    mp[{a, b}] = 1;
  }
  for (int i = 1; i <= n; ++i) e[i].push_back(arr[i]);
  for (int i = 1; i <= n; ++i) {
    for (int j = i + 1; j <= n; ++j) {
      if (!mp[{arr[i], arr[j]}])
        break;
      else
        e[j].push_back(arr[i]);
    }
  }
  int last = n;
  while (1) {
    bool ok = 1;
    for (auto v : e[last - 1])
      if (!vis[v] && mp[{v, arr[n]}]) {
        --last;
        vis[v] = 1;
        ok = 0;
        break;
      }
    if (ok) break;
  }
  cout << n - last << '\n';
  return 0;
}
