#include <bits/stdc++.h>
using namespace std;
const int maxn = 5e5 + 10;
const int inf = 0x7f7f7f7f;
int n, m;
int p[maxn], pos[maxn];
struct node {
  int u, v;
} a[maxn];
int b[maxn];
bool cmp(node x, node y) {
  if (pos[x.u] == pos[y.u]) return pos[x.v] < pos[y.v];
  return pos[x.u] < pos[y.u];
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) scanf("%d", &p[i]), pos[p[i]] = i;
  int cnt = 0;
  for (int i = 1; i <= m; i++) {
    int u, v;
    scanf("%d%d", &u, &v);
    if (pos[u] < pos[v]) cnt++, a[cnt].u = u, a[cnt].v = v;
  }
  sort(a + 1, a + cnt + 1, cmp);
  for (int i = 1; i <= cnt;) {
    int j = i + 1;
    while (a[i].u == a[j].u && j <= cnt) j++;
    j--;
    int k = i + 1;
    if (pos[a[i].v] - pos[a[i].u] != 1) {
      if (a[j].v == p[n]) b[pos[a[i].u]]++;
    } else {
      while (a[i].u == a[k].u && pos[a[k].v] - pos[a[k - 1].v] == 1 && k < j)
        k++;
      k--;
      if (a[j].v == p[n]) {
        if (j == i)
          b[pos[a[i].u]]++;
        else
          b[pos[a[k].v]]++;
      }
    }
    i = j + 1;
  }
  int ans = 0, tmp = 0;
  for (int i = n - 1; i >= 1; i--) {
    ans += b[i];
    tmp += b[i];
    tmp--;
    if (tmp < 0) break;
  }
  cout << ans << endl;
}
