#include <bits/stdc++.h>
long long gcd_(long long a, long long b) { return b ? gcd_(b, a % b) : a; }
long long lcm_(long long a, long long b) { return a / gcd_(a, b) * b; }
const long long INT_INF = 0x3f3f3f3f;
const long long INT_M_INF = 0x7f7f7f7f;
const long long LL_INF = 0x3f3f3f3f3f3f3f3f;
const long long LL_M_INF = 0x7f7f7f7f7f7f7f7f;
const long long dr[] = {0, 0, -1, 1};
const long long dc[] = {-1, 1, 0, 0};
const long long mod = 1e9 + 7;
const double pi = acos(-1.0);
const double eps = 1e-8;
const long long MAXN = 3e5 + 10;
const long long MAXT = 10000 + 10;
using namespace std;
long long n, m;
long long p[MAXN];
map<pair<long long, long long>, long long> mp;
int32_t main() {
  cin >> n >> m;
  vector<long long> v;
  for (long long i = 1; i <= n; i++) cin >> p[i];
  for (long long i = 1; i <= m; i++) {
    long long u, vv;
    cin >> u >> vv;
    if (vv == p[n]) {
      v.push_back(u);
      mp[{u, u}] = 1;
    }
    mp[{u, vv}] = 1;
  }
  long long now = 0;
  for (long long i = n - 1; i >= 1; i--) {
    long long tp = -1;
    for (long long j = now; j < v.size(); j++) {
      if (mp[{v[j], p[i]}] == 0) {
        tp = j;
      }
    }
    if (tp != -1) now = tp;
  }
  cout << v.size() - now << endl;
}
