#include <bits/stdc++.h>
using namespace std;
int a[300005];
int rev[300005];
int b[300005];
int main() {
  int n, m;
  long long ans = 0;
  scanf("%d %d", &n, &m);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
    rev[a[i]] = i;
  }
  for (int i = 0; i < m; i++) {
    int x, y;
    scanf("%d %d", &x, &y);
    x = rev[x];
    y = rev[y];
    b[max(x, y)] = max(b[max(x, y)], min(x, y));
  }
  int t = 0;
  for (int i = 1; i <= n; i++) {
    t = max(t, b[i]);
    ans += i - t;
  }
  printf("%I64d\n", ans);
  return 0;
}
