#include <bits/stdc++.h>
using namespace std;
int p[300100], a[300100], b[300100], pos[300100], r[300100];
vector<int> res[300100];
int main() {
  int n, m;
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    scanf("%d", &p[i]);
    pos[p[i]] = i;
  }
  for (int i = 1; i <= m; i++) scanf("%d %d", &a[i], &b[i]);
  for (int i = 1; i <= m; i++) {
    int L = pos[a[i]], R = pos[b[i]];
    if (L > R) swap(L, R);
    res[L].push_back(R);
  }
  r[n] = n + 1;
  for (int i = n - 1; i >= 1; i--) {
    r[i] = r[i + 1];
    for (int v : res[i]) r[i] = min(r[i], v);
  }
  long long ans = 0;
  for (int i = 1; i <= n; i++) {
    ans += (r[i] - i);
  }
  cout << ans << endl;
  return 0;
}
