#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 10;
int a[maxn];
map<pair<int, int>, int> mp;
int32_t main() {
  int n, m;
  cin >> n >> m;
  for (int i = 1; i <= n; i++) cin >> a[i];
  for (int i = 1; i <= m; i++) {
    int x, y;
    cin >> x >> y;
    mp[{x, y}]++;
  }
  int t = 0;
  for (int i = n; i >= 2; i--) {
    if (mp[{a[i - 1], a[i]}]) {
      t++;
      swap(a[i], a[i - 1]);
    } else {
      for (int j = i - 2; j >= 1; j--) {
        int x = 0;
        for (int k = j + 1; k <= i; k++) {
          if (mp[{a[j], a[k]}])
            continue;
          else {
            x = 1;
            break;
          }
        }
        if (x == 0) {
          t++;
        }
      }
      break;
    }
  }
  cout << t << endl;
}
