#include <bits/stdc++.h>
using namespace std;
int n, m;
int A[300500], pos[300500];
int pre[300500], a, b, t;
int dp[300500];
long long Ans;
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &A[i]);
    pos[A[i]] = i;
  }
  for (int i = 1; i <= m; i++) {
    scanf("%d%d", &a, &b);
    if (pos[a] < pos[b]) t = a, a = b, b = t;
    if (pos[b] > pre[pos[a]]) pre[pos[a]] = pos[b];
  }
  dp[1] = 1;
  for (int i = 2; i <= n; i++) dp[i] = min(dp[i - 1] + 1, i - pre[i]);
  for (int i = 1; i <= n; i++) {
    Ans += dp[i];
  }
  printf("%I64d\n", Ans);
  return 0;
}
