#include <bits/stdc++.h>
using namespace std;
const int maxn = 300005;
int a[maxn], pos[maxn], mx[maxn];
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
    pos[a[i]] = i;
    mx[i] = 0;
  }
  while (m--) {
    int x, y;
    scanf("%d%d", &x, &y);
    if (pos[x] > pos[y]) swap(x, y);
    mx[pos[y]] = max(mx[pos[y]], pos[x]);
  }
  long long ans = 0;
  for (int i = 1; i <= n; i++) {
    mx[i] = max(mx[i], mx[i - 1]);
    ans += i - mx[i];
  }
  printf("%lld\n", ans);
  return 0;
}
