#include <bits/stdc++.h>
using namespace std;
const int N = 3 * 100 * 1000 + 16;
int a[N];
int idx[N];
int p[N];
int main(int argc, char const *argv[]) {
  cin.sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n, k;
  cin >> n >> k;
  for (int i = 1; i <= n; ++i) {
    cin >> a[i];
    idx[a[i]] = i;
  }
  while (k--) {
    int a, b;
    cin >> a >> b;
    a = idx[a];
    b = idx[b];
    if (b < a) swap(a, b);
    if (p[a])
      p[a] = min(p[a], b);
    else
      p[a] = b;
  }
  priority_queue<pair<int, int>, vector<pair<int, int>>,
                 greater<pair<int, int>>>
      pq;
  for (int i = 1; i <= n; ++i) {
    if (p[i]) pq.push(make_pair(p[i], i));
  }
  long long ans = 0;
  int i = 1;
  int j = 1;
  while (i <= n && j <= n) {
    if ((!pq.empty() && pq.top().first > j) || pq.empty())
      j++;
    else {
      auto pp = pq.top();
      while (!pq.empty() && pq.top().first == j) {
        pp = pq.top();
        pq.pop();
      }
      int l = pp.second;
      int r = pp.first;
      if (i <= l) {
        int sz = j - i;
        ans += sz * 1ll * (sz + 1) / 2;
        int cross = r - l - 1;
        ans -= (cross * 1ll * (cross + 1) / 2);
        i = l + 1;
        j++;
      }
    }
  }
  ans += (j - i) * 1ll * (j - i + 1) / 2;
  cout << ans << endl;
  return 0;
}
