#include <bits/stdc++.h>
using namespace std;
int a[300000];
pair<int, int> x[300000], y[300000], z[300000];
int main() {
  int n, m, s, p, next_end = 0, maxn_of_l = 0, input_;
  long long ans = 0;
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    scanf("%d", &input_);
    a[input_ - 1] = i;
  }
  for (int i = 0; i < m; i++) {
    scanf("%d%d", &s, &p);
    x[i].first = max(a[s - 1], a[p - 1]);
    x[i].second = min(a[s - 1], a[p - 1]);
  }
  sort(x, x + m);
  s = 0;
  p = 0;
  while (p < n) {
    if (next_end < m && p == x[next_end].first) {
      maxn_of_l = next_end;
      while (next_end < (m - 1) && x[next_end].first == x[next_end + 1].first) {
        next_end++;
        if (x[next_end].second > x[maxn_of_l].second) maxn_of_l = next_end;
      }
      s = max(x[maxn_of_l].second + 1, s);
      next_end++;
    }
    ans += p - s + 1;
    p++;
  }
  cout << ans << endl;
  return 0;
}
