#include <bits/stdc++.h>
using namespace std;
const int MAXN = 3e5 + 5;
int a[MAXN], pos[MAXN], b[MAXN], c[MAXN];
int main() {
  int m, n, i, j, k;
  ios::sync_with_stdio(false);
  ;
  cin >> n >> m;
  for (i = 1; i <= n; i++) {
    cin >> a[i];
    pos[a[i]] = i;
    b[i] = n;
  }
  for (i = 1; i <= m; i++) {
    int x, y;
    cin >> x >> y;
    x = pos[x], y = pos[y];
    if (x > y) swap(x, y);
    b[x] = min(b[x], y - 1);
  }
  c[n] = b[n];
  for (i = n - 1; i >= 1; i--) {
    c[i] = min(b[i], c[i + 1]);
  }
  long long ans = 0;
  for (i = 1; i <= n; i++) ans += (c[i] - i + 1);
  cout << ans << endl;
}
