#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, m;
  cin >> n >> m;
  vector<long long> sootv(n);
  long long cur;
  for (long long i = 0; i < n; ++i) {
    scanf("%lld", &cur);
    cur -= 1;
    sootv[cur] = i;
  }
  long long cur1, cur2;
  set<pair<long long, long long> > set_p;
  for (long long i = 0; i < m; ++i) {
    scanf("%lld %lld", &cur1, &cur2);
    set_p.insert(make_pair(max(sootv[cur2 - 1], sootv[cur1 - 1]),
                           min(sootv[cur2 - 1], sootv[cur1 - 1])));
  }
  long long ans = 0;
  pair<long long, long long> cur_p;
  for (long long i = 0; i < n; ++i) {
    while (set_p.size() > 0 && set_p.begin()->second < i) {
      set_p.erase(set_p.begin());
    }
    if (set_p.size() == 0) {
      ans += n - i;
    } else {
      ans += set_p.begin()->first - i;
    }
  }
  cout << ans << endl;
  return 0;
}
