#include <bits/stdc++.h>
using namespace std;
const int MAX = 300005;
int pos[MAX], dp[MAX];
int main() {
  int n, m;
  while (scanf("%d%d", &n, &m) != EOF) {
    for (int i = 0; i < n; i++) {
      int x;
      scanf("%d", &x);
      pos[x] = i;
    }
    memset(dp, -1, sizeof(dp));
    while (m--) {
      int x, y;
      scanf("%d%d", &x, &y);
      int px = pos[x];
      int py = pos[y];
      if (px < py) swap(px, py);
      dp[px] = max(dp[px], py);
    }
    for (int i = 1; i < n; i++) dp[i] = max(dp[i], dp[i - 1]);
    long long ans = 0;
    for (int i = n - 1; i >= 0; i--) {
      if (dp[i] >= 0)
        ans += i - dp[i];
      else
        ans += i + 1;
    }
    printf("%I64d\n", ans);
  }
  return 0;
}
