#include <bits/stdc++.h>
using namespace std;
const long long maxn = 300005;
long long a[maxn];
vector<pair<long long, long long> > x;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  long long n, m;
  cin >> n >> m;
  for (long long i = 0; i < n; i++) {
    long long z;
    cin >> z;
    a[z - 1] = i;
  }
  for (long long i = 0; i < m; i++) {
    long long u, v;
    cin >> u >> v;
    u--;
    v--;
    u = a[u];
    v = a[v];
    if (u > v) {
      swap(u, v);
    }
    x.push_back(make_pair(u, v));
  }
  sort(x.begin(), x.end());
  long long it = m - 1;
  long long sol = 0;
  long long vege = n;
  for (long long i = n - 1; i >= 0; i--) {
    while (it >= 0 && x[it].first >= i) {
      vege = min(vege, x[it].second);
      it--;
    }
    sol += (vege - i);
  }
  cout << sol << endl;
  return 0;
}
