#include <bits/stdc++.h>
using namespace std;
vector<int> arr;
set<pair<int, int> > gr;
int solve(int pos) {
  for (int i = pos - 1; i >= 0; --i)
    if (gr.count({arr[i], arr[pos]})) {
      bool ok = true;
      for (int j = i + 1; j < pos; ++j)
        if (!gr.count({arr[i], arr[j]})) {
          ok = false;
          break;
        }
      if (ok) {
        swap(arr[i], arr[pos]);
        return pos - i + solve(i);
      }
      break;
    }
  return 0;
}
int main() {
  int n, m;
  cin >> n >> m;
  arr.resize(n);
  for (int i = 0; i < n; ++i) cin >> arr[i];
  for (int i = 0; i < m; ++i) {
    int a, b;
    cin >> a >> b;
    gr.insert({a, b});
  }
  cout << solve(n - 1) << endl;
  return 0;
}
