#include <bits/stdc++.h>
using namespace std;
int n, m;
int p[400200];
int id[400200];
int mx[400200];
int main() {
  scanf("%d", &n);
  scanf("%d", &m);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &p[i]);
  }
  for (int i = 1; i <= n; i++) {
    id[p[i]] = i;
  }
  for (int i = 1; i <= m; i++) {
    int x, y;
    scanf("%d %d", &x, &y);
    x = id[x], y = id[y];
    if (x > y) swap(x, y);
    mx[y] = max(mx[y], x);
  }
  long long answer = 0;
  for (int y = 1; y <= n; y++) {
    mx[y] = max(mx[y], mx[y - 1]);
    answer += y - mx[y];
  }
  printf("%I64d\n", answer);
  return 0;
}
