#include <bits/stdc++.h>
using namespace std;
const int module = 1e9 + 7;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  vector<long long> p(n), pos(n + 1);
  pos[0] = -1;
  for (int i = 0; i < n; ++i) {
    cin >> p[i];
    pos[p[i]] = i;
  }
  vector<long long> max_right(n, n);
  for (int i = 0; i < m; ++i) {
    int a, b;
    cin >> a >> b;
    if (pos[a] > pos[b]) swap(a, b);
    max_right[pos[a]] = min(max_right[pos[a]], pos[b]);
  }
  for (int i = n - 2; i >= 0; --i)
    max_right[i] = min(max_right[i], max_right[i + 1]);
  long long ans = 0;
  for (int i = 0; i < n; ++i) ans += (max_right[i] - i);
  cout << ans << "\n";
  return 0;
}
