#include <bits/stdc++.h>
using namespace std;
const int maxn = 4 * 100000 + 10;
int n, m;
int a[maxn], b[maxn];
int p[maxn];
int dp[maxn];
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
    p[a[i]] = i;
  }
  for (int i = 1; i <= n; i++) b[i] = 0x7FFFFFFF;
  for (int i = 1; i <= m; i++) {
    int li, ri;
    scanf("%d%d", &li, &ri);
    int fx = p[li];
    int fy = p[ri];
    if (fx > fy) swap(fx, fy);
    b[fx] = min(b[fx], fy);
  }
  dp[n] = b[n];
  for (int i = n - 1; i >= 1; i--) {
    if (b[i] == 0x7FFFFFFF)
      dp[i] = min(dp[i + 1], b[i]);
    else
      dp[i] = min(dp[i + 1], b[i] - 1);
  }
  long long ans = 0;
  for (int i = 1; i <= n; i++) {
    if (dp[i] == 0x7FFFFFFF)
      ans = ans + (long long)(n - i + 1);
    else
      ans = ans + (long long)(dp[i] - i + 1);
  }
  printf("%lld\n", ans);
  return 0;
}
