#include <bits/stdc++.h>
using namespace std;
int h[300010], id[300010], pos[300010], size, b[300010];
long long ans = 0, bit = 1;
struct cool {
  int l, r;
} a[300010];
void heapify(int i) {
  int x = h[i], t, y = id[i];
  for (; (i << 1) <= size;) {
    if ((i << 1 | 1) <= size && h[(i << 1 | 1)] < h[(i << 1)])
      t = (i << 1 | 1);
    else
      t = (i << 1);
    if (x > h[t]) {
      h[i] = h[t], pos[id[i] = id[t]] = i;
      i = t;
    } else
      break;
  }
  h[i] = x, pos[id[i] = y] = i;
}
void Build(int n) {
  size = n;
  for (int i = n / 2; i >= 1; i--) heapify(i);
}
void del(int i) {
  int p = i;
  for (; p > 1; p >>= 1) h[p] = h[p >> 1], pos[id[p] = id[p >> 1]] = p;
  h[1] = h[size], pos[id[1] = id[size--]] = 1;
  heapify(1);
}
bool cmp(cool x, cool y) { return x.l < y.l; }
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) {
    int x;
    scanf("%d", &x);
    b[x] = i;
  }
  for (int i = 1; i <= m; i++) {
    int x, y;
    scanf("%d%d", &x, &y);
    a[i].l = b[x];
    a[i].r = b[y];
    if (a[i].l > a[i].r) swap(a[i].l, a[i].r);
  }
  sort(a + 1, a + m + 1, cmp);
  for (int i = 1; i <= m; i++) h[i] = a[i].r, id[i] = i, pos[i] = i;
  Build(m);
  int len = 1;
  for (int i = 1; i <= n; i++) {
    for (; i > a[len].l && len <= m && size; len++) del(pos[len]);
    if (size <= 0)
      ans += bit * (n - i + 1);
    else
      ans += bit * (h[1] - i);
  }
  printf("%I64d", ans);
  return 0;
}
