#include <bits/stdc++.h>
const int SZ = 3e5 + 5;
using namespace std;
int n, m;
int pos[SZ], len[SZ];
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) {
    int x;
    scanf("%d", &x);
    pos[x] = i;
  }
  fill(len, len + SZ, n + 1);
  for (int i = 0; i < m; i++) {
    int x, y;
    scanf("%d%d", &x, &y);
    int a = pos[x], b = pos[y];
    if (a > b) swap(a, b);
    len[a] = min(len[a], b);
  }
  for (int i = n; i >= 1; i--) len[i] = min(len[i], len[i + 1]);
  long long res = 0;
  for (int i = 1; i <= n; i++) res += (len[i] - i);
  cout << res;
}
