#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m, x, y, one = 1;
  cin >> n >> m;
  int a[n];
  long long b[n];
  for (long long i = 0; i < n; i++) {
    scanf("%d", &a[i]);
    a[i]--;
    b[a[i]] = i;
  }
  vector<long long> c(n, -1);
  while (m--) {
    scanf("%d%d", &x, &y);
    if (x > y) {
      swap(x, y);
    }
    x--, y--;
    if (b[x] < b[y]) {
      c[b[y]] = max(c[b[y]], b[x]);
    } else {
      c[b[x]] = max(c[b[x]], b[y]);
    }
  }
  long long ans = 0;
  for (long long i = 0, j = -1; i < n; i++) {
    j = max(j, c[i]);
    ans += (i - j);
  }
  cout << ans;
  return 0;
}
