#include <bits/stdc++.h>
using namespace std;
const long long mod = 505;
const int MAX = 1e6 + 5;
int n, m, p[MAX];
set<int> S;
vector<int> v[MAX];
bool mk[MAX];
bool erase[MAX];
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> n >> m;
  for (int i = 1; i <= n; i++) cin >> p[i];
  for (int i = 1; i <= m; i++) {
    int a, b;
    cin >> a >> b;
    v[a].push_back(b);
    if (b == p[n]) mk[a] = true;
  }
  int ans = 0;
  for (int i = n; i >= 1; i--) {
    bool flag = false;
    if (mk[p[i]]) {
      bool ok = true;
      int sz = 0;
      for (int j = 0; j < v[p[i]].size(); j++) {
        int nw = v[p[i]][j];
        if (!erase[nw] && (S.find(nw) == S.end())) ok = false;
        sz++;
        sz -= erase[nw];
      }
      if (sz == (S).size()) {
        ans += ok;
        if (ok) erase[p[i]] = true;
      }
    }
    if (!erase[p[i]]) S.insert(p[i]);
  }
  cout << ans << "\n";
}
