#include <bits/stdc++.h>
using namespace std;
const int N = 4e5 + 5;
int a[N], pos[N], mx[N];
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    pos[a[i]] = i;
    mx[i] = 0;
  }
  while (m--) {
    int x, y;
    cin >> x >> y;
    if (pos[x] > pos[y]) swap(x, y);
    mx[pos[y]] = max(mx[pos[y]], pos[x]);
  }
  long long ans = 0;
  for (int i = 1; i <= n; i++) {
    mx[i] = max(mx[i], mx[i - 1]);
    ans += i - mx[i];
  }
  cout << ans << endl;
  return 0;
}
