#include <bits/stdc++.h>
using namespace std;
const long long inf = 1000000000000000000;
const long long maxn = 1000002;
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long n, m;
  cin >> n >> m;
  vector<long long> v(n);
  for (long long c = 0; c < n; c++) cin >> v[c];
  map<long long, long long> ma;
  for (long long c = 0; c < n; c++) ma[v[c]] = c;
  vector<long long> dop(n, n), dop2(n, -1);
  for (long long c = 0; c < m; c++) {
    long long e, e1;
    cin >> e >> e1;
    if (ma[e] > ma[e1]) swap(e, e1);
    dop[e] = min(dop[e], e1);
    dop2[ma[e1]] = max(dop2[ma[e1]], ma[e]);
  }
  long long l = 0, r = 0, answ = 0;
  for (long long i = 0; i < n; i++) {
    while (dop2[i] >= l) l++;
    answ += i - l + 1;
  }
  cout << answ;
  return 0;
}
