#include <bits/stdc++.h>
using namespace std;
const int N = 3 * 1e5 + 10;
const int INF = 1e9;
int a[N], pos[N];
int dist[N];
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;
    dist[i] = INF;
  }
  for (int i = 0; i < m; ++i) {
    int l, r;
    scanf("%d %d", &l, &r);
    int p1 = pos[r], p2 = pos[l];
    if (p1 > p2 && p1 < dist[p2]) {
      dist[p2] = p1;
    } else if (p1 < p2 && p2 < dist[p1]) {
      dist[p1] = p2;
    }
  }
  for (int i = n - 1; i >= 1; --i) {
    if (dist[i + 1] < dist[i]) {
      dist[i] = dist[i + 1];
    }
  }
  long long ans = 0;
  for (int i = 1; i <= n; ++i) {
    if (dist[i] != INF) {
      ans += (long long)(dist[i] - i);
    } else {
      ans += (long long)(n - i + 1);
    }
  }
  printf("%lld\n", ans);
  return 0;
}
