#include <bits/stdc++.h>
using namespace std;
int n, m;
int a[303030];
int b[303030];
int bad[303030];
int R[303030];
int main() {
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    scanf("%d", &a[i]), a[i]--;
    b[a[i]] = i;
    R[i] = 303000;
  }
  for (int i = 0; i < m; i++) {
    int u, v;
    scanf("%d %d", &u, &v);
    u--;
    v--;
    u = b[u];
    v = b[v];
    if (u > v) swap(u, v);
    R[u] = min(R[u], v);
  }
  long long ans = 0;
  int j = 0;
  for (int i = 0; i < n; i++) {
    while (j < n && bad[j] == 0) {
      bad[R[j]]++;
      j++;
    }
    ans += n - j;
    bad[R[i]]--;
  }
  ans = (long long)n * (n + 1) / 2 - ans;
  cout << ans << endl;
}
