#include <bits/stdc++.h>
using namespace std;
long long const N = 5e5 + 10;
long long const MOD = 1e9 + 7;
struct demo {
  long long left, right;
};
long long n, m;
map<long long, long long> smap;
vector<long long> store[N];
demo num[N];
set<long long, greater<long long> > last;
bool check(long long a, long long b) {
  if (num[a].right == b) {
    long long prev = num[a].left;
    long long nxt = num[b].right;
    num[b].left = prev;
    num[b].right = a;
    num[a].left = b;
    num[a].right = nxt;
    num[prev].right = b;
    num[nxt].left = a;
    return true;
  }
  return false;
}
int32_t main() {
  scanf("%d %d", &n, &m);
  for (long long i = 1; i <= n; i++) {
    long long a;
    cin >> a;
    smap[a] = i;
    num[i].left = i - 1;
    num[i].right = i + 1;
  }
  for (long long i = 1; i <= m; i++) {
    long long a, b;
    scanf("%d %d", &a, &b);
    a = smap[a];
    b = smap[b];
    if (b == n) {
      last.insert(a);
    }
    if (a < b) store[a].push_back(b);
  }
  for (long long i = 1; i <= n; i++) {
    sort(store[i].begin(), store[i].end());
  }
  for (auto temp : last) {
    for (long long j = 0; j < store[temp].size(); j++) {
      long long t1 = store[temp][j];
      check(temp, t1);
    }
  }
  long long sum = 0;
  long long tot = n;
  while (n != 0) {
    n = num[n].left;
    sum++;
  }
  scanf("%d\n", tot - sum);
}
