#include <bits/stdc++.h>
using namespace std;
const int N = 1000006;
const int K = (int)log2(N) + 2;
const int SQRTN = (int)sqrt(N) + 7;
const long long infi = 1ll << 60;
long long n, m, a, idx[N], x, y, len[N], ans;
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  ;
  cin >> n >> m;
  for (int(i) = (0); (i) <= (int)(n - 1); ++(i)) cin >> a, idx[a] = i;
  fill(len, len + n, n - 1);
  for (int(i) = (0); (i) <= (int)(m - 1); ++(i)) {
    cin >> x >> y;
    x = idx[x], y = idx[y];
    if (x > y) swap(x, y);
    len[x] = min(len[x], y - 1);
  }
  for (int(i) = (n - 2); (i) >= (0); --(i)) len[i] = min(len[i], len[i + 1]);
  for (int(i) = (0); (i) <= (int)(n - 1); ++(i)) ans += (len[i] - i + 1);
  cout << ans << endl;
  return 0;
}
