#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m, A[300030], B[300030], C[300030], a, b;
  while (scanf("%d %d\n", &n, &m) != EOF) {
    for (int i = 0; i < n; i++) {
      scanf("%d", &A[i]);
      B[A[i]] = i;
    }
    memset(C, -1, n * 4);
    while (m--) {
      scanf("%d %d", &a, &b);
      a = B[a];
      b = B[b];
      if (a > b) swap(a, b);
      if (C[a] == -1)
        C[a] = b;
      else
        C[a] = min(C[a], b);
    }
    C[n] = n;
    long long r = 0;
    for (int i = n - 1; i >= 0; i--) {
      if (C[i] == -1)
        C[i] = C[i + 1];
      else
        C[i] = min(C[i], C[i + 1]);
      r += (long long)C[i] - (long long)i;
    }
    printf("%I64d\n", r);
  }
  return 0;
}
