#include <bits/stdc++.h>
using namespace std;
long long n, m, a[300005];
long long pos[300005];
long long en[300005];
int main() {
  scanf("%lld", &n);
  scanf("%lld", &m);
  for (int i = 0; i < n; i++) {
    scanf("%lld", &a[i]);
    pos[a[i]] = i + 1;
  }
  for (int i = 0; i < m; i++) {
    long long x, y;
    scanf("%lld", &x);
    scanf("%lld", &y);
    x = pos[x];
    y = pos[y];
    if (x > y) swap(x, y);
    if (en[x] == 0) {
      en[x] = y;
    } else {
      en[x] = min(en[x], y);
    }
  }
  long long ans = 0;
  long long mx = n + 1;
  for (long long i = n; i > 0; i--) {
    if (en[i] == 0) {
      ans += mx - i;
    } else {
      mx = min(mx, en[i]);
      ans += (mx - i);
    }
  }
  cout << ans << endl;
  return 0;
}
