#include <bits/stdc++.h>
using namespace std;
const int MOD = 1000000007;
int track[300001], k;
long long lans = 0, n, m, curcount = 0;
pair<int, int> foe[300001];
bool comp(pair<int, int> a, pair<int, int> b) {
  if (a.second > b.second)
    return true;
  else if (a.second == b.second)
    return a.first > b.first;
  return false;
}
int main() {
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    scanf("%d", &k);
    track[k] = i;
  }
  for (int i = 0; i < m; i++) {
    pair<int, int> k;
    scanf("%d%d", &k.first, &k.second);
    foe[i] = make_pair(min(track[k.first], track[k.second]) + 1,
                       n - max(track[k.first], track[k.second]));
  }
  sort(foe, foe + m, comp);
  for (int i = 0; i < m; i++) {
    if (foe[i].first > curcount) {
      lans += (foe[i].first - curcount) * foe[i].second;
      curcount = foe[i].first;
    }
  }
  cout << (n * (n + 1) / 2 - lans);
  return 0;
}
