#include <bits/stdc++.h>
using namespace std;
const int inf = 1e9 + 7;
int n, m, p[1000111], r[1000111], d[1000111], l[1000111];
int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    cin >> p[i];
    d[p[i]] = i;
    l[p[i]] = 0;
    r[p[i]] = n + 1;
  }
  while (m--) {
    int x, y;
    cin >> x >> y;
    if (d[x] > d[y]) swap(x, y);
    r[x] = min(r[x], d[y]);
    l[y] = max(l[y], d[x]);
  }
  int last = 0;
  long long res = 0;
  for (int i = 1; i <= n; i++) {
    last = max(last, l[p[i]]);
    res += i - last;
  }
  cout << res;
}
