#include <bits/stdc++.h>
using namespace std;
long long n, m, p[1000000], o[1000000], b[1000000], ans, r, x, y;
int main() {
  cin >> n >> m;
  for (long long i = 0; i < n; i++) {
    scanf("%d", &p[i]);
    b[p[i]] = i;
    o[i] = n;
  }
  for (long long j = 0; j < m; j++) {
    scanf("%d%d", &x, &y);
    if (b[x] > b[y]) swap(x, y);
    o[b[x]] = min(o[b[x]], b[y]);
  }
  r = n;
  for (long long i = n - 1; i > -1; i--) {
    r = min(r, o[i]);
    ans += r - i;
  }
  cout << ans;
}
