#include <bits/stdc++.h>
using namespace std;
vector<pair<int, int> > v;
int arr[300000], reversed[300001];
int cache[300000];
int main() {
  int n, m;
  scanf("%d %d", &n, &m);
  for (int i = 0; i < n; i++) {
    scanf("%d", arr + i);
    reversed[arr[i]] = i;
  }
  if (n == 1) {
    printf("1");
    return 0;
  }
  int a, b, c, d;
  for (int i = 0; i < m; i++) {
    scanf("%d %d", &a, &b);
    c = min(reversed[a], reversed[b]);
    d = max(reversed[a], reversed[b]);
    v.push_back(make_pair(c, d));
  }
  sort(v.begin(), v.end());
  int v_idx = 0;
  long long result = 0;
  int min_val = 987654321;
  for (int i = m - 1; i >= 0; i--) {
    min_val = min(min_val, v[i].second);
    cache[v[i].first] = min_val;
  }
  for (int i = 0; i < n; i++) {
    while (v_idx < v.size() && v[v_idx].first < i) v_idx++;
    if (v_idx < v.size())
      result += (cache[v[v_idx].first] - i);
    else
      result += (n - i);
  }
  cout << result;
}
