#include <bits/stdc++.h>
const double pi = 3.141592653589793238462643383279;
using namespace std;
const long double EPS = 1e-6, PI = acos((long double)-1);
int arr[301010];
int L[301010], R[301010];
vector<vector<int>> rl(301010);
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(4);
  int n, m;
  cin >> n >> m;
  vector<int> p(n);
  for (int i = 0; i < (int)n; ++i) {
    cin >> p[i];
    arr[p[i]] = i;
  }
  long long ans = 0;
  vector<pair<int, int>> vp;
  set<pair<int, int>> st;
  for (int i = 0; i < (int)m; ++i) {
    cin >> L[i] >> R[i];
    if (arr[L[i]] > arr[R[i]]) {
      swap(L[i], R[i]);
    }
    rl[arr[L[i]] + 1].push_back(i);
    st.insert({arr[R[i]], i});
  }
  st.insert({INT_MAX, 0});
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < rl[i].size(); j++) {
      int idx = rl[i][j];
      st.erase(make_pair(arr[R[idx]], idx));
    }
    auto itr = st.lower_bound(make_pair(i, -1));
    if (itr->first == INT_MAX) {
      ans += n - i;
    } else
      ans += itr->first - i;
  }
  cout << ans << endl;
  return 0;
}
