#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
const long double eps = 1e-7;
const int inf = 1000000010;
const long long INF = 10000000000000010LL;
const int mod = 1000000007;
const int MAXN = 100010, LOG = 20;
int n, m, k, u, v, x, y, t, root, ans;
int P[MAXN];
int pos[MAXN];
int dist[MAXN];
vector<int> L[MAXN], R[MAXN];
vector<int> G[MAXN];
queue<int> q;
queue<int> Q;
map<int, bool> mp[MAXN];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    cin >> P[i];
    pos[P[i]] = i;
  }
  root = P[n];
  while (m--) {
    cin >> u >> v;
    G[v].push_back(u);
    G[u].push_back(v);
    mp[v][u] = 1;
  }
  for (int i = 2; i <= n; i++)
    if (mp[P[i]][P[i - 1]]) Q.push(i);
  while (!Q.empty()) {
    int v = Q.front();
    Q.pop();
    if (!mp[P[v]][P[v - 1]]) continue;
    mp[P[v]][P[v - 1]] = 0;
    swap(P[v], P[v - 1]);
    if (mp[P[v - 1]][P[v - 2]]) Q.push(v - 1);
    if (mp[P[v + 1]][P[v]]) Q.push(v + 1);
  }
  for (int i = 1; i <= n; i++)
    if (P[i] == root) return cout << n - i << '\n', 0;
  ;
  return 0;
}
