#include <bits/stdc++.h>
using namespace std;
struct point {
  int l, r;
};
int a[300300];
int n, m, x;
point b[300300];
long long ans;
bool cmp(point a, point b) { return a.l < b.l; }
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &x);
    a[x] = i;
  }
  for (int i = 1; i <= m; i++) scanf("%d%d", &b[i].l, &b[i].r);
  for (int i = 1; i <= m; i++) {
    b[i].l = a[b[i].l];
    b[i].r = a[b[i].r];
    if (b[i].l > b[i].r) swap(b[i].l, b[i].r);
  }
  sort(b + 1, b + m + 1, cmp);
  a[m] = b[m].r;
  a[m + 1] = n + 1;
  for (int i = m - 1; i > 0; --i)
    a[i] = (a[i + 1] < b[i].r ? a[i + 1] : b[i].r);
  int j = 1;
  for (int i = 1; i <= n; i++) {
    while (j <= m && b[j].l < i) ++j;
    ans += a[j] - i;
  }
  printf("%I64d", ans);
  return 0;
}
