#include <bits/stdc++.h>
using namespace std;
const long long sz = 3e5 + 10;
long long ara[sz], pos[sz], other[sz], mn[sz];
int main() {
  long long n, m;
  cin >> n >> m;
  for (long long i = 1; i <= n; ++i) {
    scanf("%lld", &ara[i]);
    pos[ara[i]] = i;
  }
  for (long long i = 1; i <= n; ++i) other[i] = mn[i] = n + 1;
  for (long long i = 1; i <= m; ++i) {
    long long p1, p2;
    scanf("%lld", &p1), scanf("%lld", &p2);
    if (pos[p1] > pos[p2]) swap(p1, p2);
    other[pos[p1]] = min(other[pos[p1]], pos[p2]);
  }
  mn[n + 1] = n + 1;
  for (long long i = n; i >= 1; --i) mn[i] = min(mn[i + 1], other[i]);
  long long ans = 0;
  for (long long i = 1; i <= n; ++i) ans += (mn[i] - i);
  cout << ans << '\n';
  return 0;
}
