#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];
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);
  for (int i = 1; i <= n; ++i) {
    int q;
    scanf("%d", &q);
    a[q] = i;
  }
  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);
  set<int> s;
  s.clear();
  int ans = 0;
  for (int i = 1; i <= m; ++i) {
    if (b[i].y == n) {
      int t = 1;
      int k = i + 1;
      for (int j = i + 1; j <= m; ++j) {
        if (b[j].x == b[i].x && b[j].y > n - t) continue;
        while (s.count(n - t)) {
          t++;
          if (n - t == b[i].x) {
            s.insert(b[i].x);
            ans++;
            k = j;
            break;
          }
        }
        if (b[j].x == b[i].x && b[j].y + t == n) {
          t++;
          int ok = 0;
          while (s.count(n - t)) {
            t++;
            if (n - t == b[i].x) {
              s.insert(b[i].x);
              ans++;
              ok = 1;
              break;
            }
          }
          if (!ok && b[i].x + 1 == b[j].y) {
            s.insert(b[i].x);
            ++ans;
          }
        } else {
          k = j;
          break;
        }
      }
      if (i == k - 1) {
        if (b[i].x + 1 == b[i].y) ans++;
      }
      i = k - 1;
    }
  }
  printf("%d\n", ans);
}
int main() {
  work();
  return 0;
}
