#include <bits/stdc++.h>
using namespace std;
int n, m;
vector<int> ve;
map<int, int> me;
int vw[300009];
int main() {
  scanf("%d", &(n));
  scanf("%d", &(m));
  int e;
  for (int i = 0; i < n; i++) {
    scanf("%d", &(e));
    ve.push_back(e);
    me[e] = i;
  }
  int a, b;
  int ma, mb;
  for (int i = 0; i < m; i++) {
    scanf("%d", &(a));
    scanf("%d", &(b));
    ma = me[a];
    mb = me[b];
    if (ma > mb) swap(ma, mb);
    vw[mb] = max(vw[mb], ma + 1);
  }
  long long res = 0;
  int p = 0;
  for (int i = 0; i < n; i++) {
    p = max(p, vw[i]);
    res = res + (i - p + 1ll);
  }
  cout << res << endl;
  return 0;
}
