#include <bits/stdc++.h>
using namespace std;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, 1, 0, -1};
const int dxo[8] = {-1, -1, -1, 0, 1, 1, 1, 0};
const int dyo[8] = {-1, 0, 1, 1, 1, 0, -1, -1};
inline bool is_down(char x) { return ('a' <= x && x <= 'z'); }
inline bool is_upper(char x) { return ('A' <= x && x <= 'Z'); }
inline bool is_digit(char x) { return ('0' <= x && x <= '9'); }
inline int read() {
  int x = 0, f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = 10 * x + ch - '0';
    ch = getchar();
  }
  return x * f;
}
inline long long readll() {
  long long x = 0, f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = 10 * x + ch - '0';
    ch = getchar();
  }
  return x * f;
}
long long gcd(long long x, long long y) { return y ? gcd(y, x % y) : x; }
long long power(long long x, long long y) {
  long long t = 1;
  for (; y; y >>= 1, x = x * x % 1000000007)
    if (y & 1) t = t * x % 1000000007;
  return t;
}
struct edge {
  int go, next;
} e[1000005];
int tot, head[100000 + 5];
void insert(int u, int v) {
  e[++tot] = (edge){v, head[u]};
  head[u] = tot;
}
int n, m, sum;
int a[300005];
int s[300005];
int t[300005];
int fin;
bool cmp(int x, int y) { return x > y; }
int main() {
  n = read();
  m = read();
  for (int i = 1; i <= (n); i++) a[i] = read(), t[a[i]] = i;
  fin = a[n];
  s[++sum] = n;
  for (int i = 1; i <= (m); i++) {
    int x, y;
    x = read();
    y = read();
    insert(x, y);
    if (x == fin) s[++sum] = t[y];
    if (y == fin) s[++sum] = t[x];
  }
  sort(s + 1, s + sum + 1, cmp);
  int now = 0, tt = 0;
  memset(t, 0, sizeof(t));
  for (int i = 2; i <= sum; i++) {
    int ttt = 0;
    now += s[i - 1] - 1 - (s[i] + 1) + 1;
    int r = s[i - 1] - 1, l = s[i] + 1;
    while (l <= r) {
      t[a[l]] = 1;
      l++;
    }
    int tmp = a[s[i]];
    for (int j = head[tmp], y = e[j].go; j; j = e[j].next, y = e[j].go)
      if (t[y] == 1) ttt++;
    if (ttt != now) {
      now++;
      t[tmp] = 1;
    } else
      tt++;
  }
  cout << tt << endl;
  return 0;
}
