#include <bits/stdc++.h>
using namespace std;
const long long maxn = 1e6 + 1, mod = 1e9 + 7;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n, m;
  cin >> n >> m;
  int ar[n + 1];
  for (long long i = 1; i <= n; i++) {
    int x;
    cin >> x;
    ar[x] = i;
  }
  int mim[n + 1];
  memset(mim, 0, sizeof(mim));
  while (m--) {
    int x, y;
    cin >> x >> y;
    x = ar[x];
    y = ar[y];
    if (y < x) swap(x, y);
    mim[y] = max(mim[y], x);
  }
  long long ans = 0;
  int now = 0;
  for (long long i = 1; i <= n; i++) {
    now = max(now, mim[i]);
    ans += i - now;
  }
  cout << ans;
  return 0;
}
