#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long i, j, n, m, ans, x, y;
  cin >> n >> m;
  long long a[n + 1], pos[n + 1];
  for (i = 1; i <= n; ++i) {
    cin >> a[i];
    pos[a[i]] = i;
  }
  map<long long, set<long long> > mp;
  set<long long>::iterator it1;
  set<pair<long long, long long> > st;
  set<pair<long long, long long> >::iterator it;
  for (i = 0; i < m; ++i) {
    cin >> x >> y;
    x = pos[x];
    y = pos[y];
    if (x > y) swap(x, y);
    mp[x].insert(y);
    st.insert({y, x});
  }
  ans = 0;
  for (i = 1; i <= n; ++i) {
    if (!st.empty()) {
      ans += (st.begin()->first) - i;
    } else {
      ans += n - i + 1;
    }
    for (it1 = mp[i].begin(); it1 != mp[i].end(); ++it1) st.erase({*it1, i});
  }
  cout << ans;
  return 0;
}
