#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e6 + 5;
int f[maxn], pos[maxn];
int main(void) {
  int n, m;
  while (cin >> n >> m) {
    for (int i = 1; i <= n; i++) {
      int t;
      scanf("%d", &t);
      pos[t] = i;
      f[i] = n;
    }
    for (int i = 1; i <= m; i++) {
      int x, y;
      scanf("%d%d", &x, &y);
      int l = min(pos[x], pos[y]);
      int r = max(pos[x], pos[y]);
      f[l] = min(f[l], r - 1);
    }
    for (int i = n - 1; i >= 1; i--) f[i] = min(f[i], f[i + 1]);
    long long ans = 0;
    for (int i = 1; i <= n; i++) ans += f[i] - i + 1;
    printf("%I64d\n", ans);
  }
  return 0;
}
