#include <bits/stdc++.h>
using namespace std;
const int N = 300005;
long long a, ans, n, m, x, y, pos[N], lpos[N], t = 1;
int main() {
  scanf("%lld%lld", &n, &m);
  for (int i = 1; i <= n; i++) {
    scanf("%lld", &a);
    pos[a] = i;
  }
  for (int k = 1; k <= m; k++) {
    scanf("%lld%lld", &x, &y);
    if (pos[x] > pos[y]) swap(x, y);
    lpos[pos[y]] = max(lpos[pos[y]], pos[x] + 1);
  }
  for (int i = 1; i <= n; i++) {
    t = max(t, lpos[i]);
    ans += (long long)i - (long long)t + 1;
  }
  printf("%lld", ans);
  return 0;
}
