#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e9;
const long long MD = 1e9 + 7;
const long long MAXN = (1 << 17);
const long long BASE = 1e9;
const long double EPS = 1e-9;
const long double pi = acos(-1);
long long a[1000006];
vector<long long> g[1000006];
map<long long, long long> mp[1000006];
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long n, m;
  cin >> n >> m;
  for (long long i = 1; i <= n; i++) {
    cin >> a[i];
  }
  for (long long i = 1; i <= m; i++) {
    long long v, u;
    cin >> v >> u;
    mp[u][v] = 1;
    mp[v][u] = 1;
  }
  set<long long> s;
  for (auto j : g[a[n]]) {
    s.insert(j);
  }
  long long MAXANS = s.size();
  vector<vector<long long>> bads;
  bads.push_back({0});
  for (long long i = 1; i < n; i++) {
    bool ok = false;
    if (mp[a[i]][a[n]] == 1) ok = 1;
    if (!ok) {
      bads.back().push_back(a[i]);
    } else {
      bads.push_back({a[i]});
    }
  }
  long long ans = 0;
  for (long long i = bads.size() - 1; i > 0; i--) {
    if (bads[i].size() == 1) {
      ans++;
    } else {
      long long cur = bads[i].front();
      for (long long j = 1; j < bads[i].size(); j++) {
        if (!mp[cur][bads[i][j]]) {
          bads[i - 1].push_back(cur);
          ans--;
        }
        bads[i - 1].push_back(bads[i][j]);
      }
      ans++;
    }
  }
  cout << ans;
}
