#include <bits/stdc++.h>
using namespace std;
int n, m;
int mass[1000000] = {0};
pair<int, int> pairs[1000000];
int pfff[1000000] = {0};
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 0; i < n; i++) {
    int a;
    scanf("%d", &a);
    mass[a] = i + 1;
  }
  for (int i = 1; i <= m; i++) {
    int a, b;
    scanf("%d%d", &a, &b);
    if (mass[a] > mass[b]) swap(a, b);
    pairs[i].first = mass[a];
    pairs[i].second = mass[b];
    if (pfff[mass[b]]) {
      if (pairs[pfff[mass[b]]].first < mass[a]) pfff[mass[b]] = i;
    } else {
      pfff[mass[b]] = i;
    }
  }
  int r = 0;
  long long ans = 0;
  for (int i = 1; i <= n; i++) {
    if (pfff[i]) r = max(r, pairs[pfff[i]].first);
    ans += i - r;
  }
  cout << ans;
  return 0;
}
