#include <bits/stdc++.h>
using namespace std;
void FAST() {
  std::ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
}
void solve() {}
vector<int> mp[500007];
int main() {
  FAST();
  int n, m;
  cin >> n >> m;
  int arr[n];
  for (int first = 0; first < n; ++first) cin >> arr[first];
  for (int first = 0; first < m; ++first) {
    int x, y;
    cin >> x >> y;
    mp[y].push_back(x);
  }
  int ans = 0;
  vector<int> p;
  for (int first = n - 2; first >= 0; --first) {
    if (!binary_search(mp[arr[n - 1]].begin(), mp[arr[n - 1]].end(),
                       arr[first])) {
      p.push_back(arr[first]);
    } else {
      for (auto it : p) {
        if (!binary_search(mp[it].begin(), mp[it].end(), arr[first])) {
          cout << ans;
          return 0;
        }
      }
      ans++;
    }
  }
  cout << ans;
  return 0;
}
