#include <bits/stdc++.h>
const int N = 300005;
using namespace std;
int pos[N], f[N];
int main() {
  int n, m, v, a, b;
  ios::sync_with_stdio(false);
  cin.tie(0);
  ;
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    cin >> v;
    pos[v] = i;
    f[i] = n + 1;
  }
  for (int i = 1; i <= m; i++) {
    cin >> a >> b;
    if (pos[a] > pos[b]) swap(a, b);
    f[pos[a]] = min(pos[b], f[pos[a]]);
  }
  long long ans = 1ll * n * (n - 1) / 2 + n;
  for (int i = n - 1; i >= 1; i--) {
    f[i] = min(f[i], f[i + 1]);
  }
  for (int i = 1; i < n; i++) {
    ans -= (n - f[i] + 1);
  }
  cout << ans << "\n";
}
