#include <bits/stdc++.h>
using namespace std;
const int inf = 1e9;
const int MOD = 1e9 + 7;
const int N = 3e5 + 10;
int n, f[N], pos[N];
long long prepare() {
  int m, x, y;
  scanf("%d%d", &n, &m);
  for (auto i = (1); i <= (n); i++) {
    scanf("%d", &x);
    pos[x] = i;
  }
  while (m--) {
    scanf("%d%d", &x, &y);
    x = pos[x];
    y = pos[y];
    if (x > y) swap(x, y);
    f[y] = max(f[y], x);
  }
  long long ans = 0;
  for (auto i = (1); i <= (n); i++) {
    f[i] = max(f[i], f[i - 1]);
    ans += i - f[i];
  }
  return ans;
}
int main() { cout << prepare(); }
