#include <bits/stdc++.h>
using namespace std;
int ind[300005 + 5];
int n, m, i, num, x, y;
int minimum[300005 + 5];
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  int n, m, i, num, x, y;
  cin >> n >> m;
  for (i = 1; i <= n; i++) {
    cin >> num;
    ind[num] = i;
    minimum[i] = n;
  }
  for (i = 1; i <= m; i++) {
    cin >> x >> y;
    x = ind[x];
    y = ind[y];
    if (x > y) swap(x, y);
    minimum[x] = min(minimum[x], y - 1);
  }
  long long ans = 0;
  int l = n;
  for (i = n; i >= 1; i--) {
    l = min(minimum[i], l);
    ans += (l - i + 1);
  }
  cout << ans << "\n";
}
