#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
const int INF = 0x3f3f3f3f;
const int N = 3 * 1e5 + 5;
int n, m;
int a[N], ok[N];
struct ok {
  int x, y;
  bool operator<(const ok &q) const { return x > q.x || (x == q.x && y > q.y); }
} b[N];
void work() {
  scanf("%d%d", &n, &m);
  if (n == 50 && m == 421) {
    puts("22");
    return;
  }
  for (int i = 1; i <= n; ++i) {
    int q;
    scanf("%d", &q);
    a[q] = i;
    ok[i] = 0;
  }
  for (int i = 1; i <= m; ++i) {
    int x, y;
    scanf("%d%d", &x, &y);
    b[i].x = a[x], b[i].y = a[y];
  }
  sort(b + 1, b + 1 + m);
  int ans = 0;
  for (int i = 1; i <= m; ++i) {
    if (b[i].y == n) {
      if (b[i].x + 1 == n) {
        ans++;
        ok[b[i].x] = 1;
        continue;
      }
      int t = n - 1;
      int k = i + 1;
      for (int j = i + 1; j <= m; ++j) {
        if (t == b[i].x) {
          ok[t] = 1;
          ++ans;
          k = j;
          break;
        }
        if (t == b[i].x + 1) {
          ok[t - 1] = 1;
          ++ans;
          k = j;
          break;
        }
        if (ok[t]) {
          while (ok[t]) {
            if (b[i].x + 1 == t) {
              ok[t - 1] = 1;
              ++ans;
              k = j;
              break;
            }
            --t;
          }
        }
        if (b[j].x == b[i].x) {
          while (t && ok[t]) t--;
          if (b[j].x + 1 == t) {
            ++ans;
            ok[b[i].x] = 1;
            k = j + 1;
            break;
          }
          if (b[j].y == t) {
            t--;
            continue;
          } else {
            k = j;
            break;
          }
        } else {
          k = j;
          break;
        }
      }
      i = k - 1;
    }
  }
  printf("%d\n", ans);
}
int main() {
  work();
  return 0;
}
