#include <bits/stdc++.h>
using namespace std;
const int oo = 0x3f3f3f3f;
int id[3000000], l[3000000];
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  for (int(i) = (0); (i) < (n); ++(i)) {
    int x;
    scanf("%d", &x);
    id[x] = i;
    l[i] = -1;
  }
  for (int(i) = (0); (i) < (m); ++(i)) {
    int a, b;
    scanf("%d%d", &a, &b);
    a = id[a], b = id[b];
    if (a > b) swap(a, b);
    l[b] = max(l[b], a);
  }
  long long s = 0;
  int k = -1;
  for (int(i) = (0); (i) < (n); ++(i)) {
    k = max(k, l[i]);
    l[i] = max(l[i], k);
    s += (i - l[i]);
  }
  printf("%lld\n", s);
  return 0;
}
