#include <bits/stdc++.h>
using namespace std;
long long int pos[1000010], arr[1000010];
long long int most_nearest[1000010];
long long int lmin(long long int a, long long int b) {
  if (a < b) return a;
  return b;
}
int main() {
  long long int N, M, u, v;
  scanf("%lld %lld", &N, &M);
  for (int i = 1; i <= N; i++) {
    scanf("%lld", &arr[i]);
    pos[arr[i]] = i;
    most_nearest[i] = N;
  }
  long long int p, q;
  for (int i = 1; i <= M; i++) {
    scanf("%lld %lld", &u, &v);
    p = pos[u];
    q = pos[v];
    if (q > p)
      most_nearest[p] = min(most_nearest[p], q - 1);
    else
      most_nearest[q] = min(most_nearest[q], p - 1);
  }
  most_nearest[N] = N;
  for (int i = N - 1; i >= 1; i--)
    most_nearest[i] = lmin(most_nearest[i], most_nearest[i + 1]);
  long long int ans = 0, diff;
  for (long long int i = 1; i <= N; i++) {
    ans = ans + (most_nearest[i] - i + 1);
  }
  cout << ans << endl;
  return 0;
}
