#include <bits/stdc++.h>
const int MAXN = 3e5 + 5;
int n, m, p[MAXN], ps[MAXN];
int a[MAXN], b[MAXN];
std::vector<int> G[MAXN];
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; ++i) scanf("%d", p + i), ps[p[i]] = i;
  for (int i = 1; i <= m; ++i) scanf("%d%d", a + i, b + i);
  for (int i = 1; i <= m; ++i)
    if (ps[a[i]] < ps[b[i]]) std::swap(a[i], b[i]);
  for (int i = 1; i <= m; ++i) G[ps[a[i]]].push_back(ps[b[i]]);
  long long ans = 0;
  int mx = 0;
  for (int i = 1; i <= n; ++i) {
    for (auto x : G[i]) mx = std::max(mx, x);
    ans += i - mx;
  }
  printf("%lld\n", ans);
  return 0;
}
