#include <bits/stdc++.h>
using namespace std;
const int maxn = 3e5 + 10;
int p[maxn], dp[maxn];
int n, m;
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; ++i) {
    int t;
    scanf("%d", &t);
    p[t] = i;
  }
  for (int i = 0; i < m; ++i) {
    int a, b;
    scanf("%d%d", &a, &b);
    int pa = min(p[a], p[b]);
    int pb = max(p[a], p[b]);
    if (dp[pa])
      dp[pa] = min(dp[pa], pb);
    else
      dp[pa] = pb;
  }
  long long ans = 1;
  dp[n] = 1;
  for (int i = n - 1; i > 0; --i) {
    if (!dp[i]) {
      dp[i] = dp[i + 1] + 1;
    } else {
      dp[i] = min(dp[i] - i, dp[i + 1] + 1);
    }
    ans += dp[i];
  }
  printf("%I64d\n", ans);
  return 0;
}
