#include <bits/stdc++.h>
using namespace std;
struct s {
  int i, id;
};
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n, m;
  cin >> n >> m;
  s a[n + 1];
  for (int i = 1; i <= n; i++) cin >> a[i].id, a[i].i = i;
  int lst = a[n].id;
  for (int i = 1; i <= m; i++) {
    int u, v;
    cin >> u >> v;
    int x, y;
    for (int i = 1; i <= n; i++) {
      if (a[i].i == u) {
        x = i;
        break;
      }
    }
    for (int i = 1; i <= n; i++) {
      if (a[i].i == v) {
        y = i;
        break;
      }
    }
    if (abs(x - y) == 1) {
      swap(a[x], a[y]);
    }
  }
  int ans = 0;
  for (int i = n; i > 0; i--) {
    if (a[i].id == lst) {
      ans = abs(n - i);
    }
  }
  cout << ans;
  exit(0);
}
