#include <bits/stdc++.h>
using namespace std;
int n, m, p[310000], du[310000], xx, yy, ans;
map<long long, bool> ms;
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) scanf("%d", &p[i]);
  for (int i = 1; i <= m; i++) {
    scanf("%d%d", &xx, &yy);
    du[xx]++;
    ms[(xx * 1ll * (n + 1) + yy)] = 1;
  }
  for (int i = n - 1; i >= 1; i--)
    if (du[p[i]] >= n - i) {
      bool ok = 1;
      for (int j = i + 1; j <= n; j++)
        if (!ms[(p[i] * 1ll * (n + 1) + p[j])]) {
          ok = 0;
          break;
        }
      if (ok) ans++;
    }
  printf("%d\n", ans);
}
