#include <bits/stdc++.h>
using namespace std;
int a[300005];
int minn[300005];
map<int, int> M;
int main() {
  ios_base::sync_with_stdio(0);
  memset(minn, 1000000, sizeof minn);
  int n, m, ax, bx;
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; ++i) {
    scanf("%d", &a[i]);
    M[a[i]] = i;
  }
  for (int i = 0; i < m; ++i) {
    scanf("%d%d", &ax, &bx);
    if (M[ax] > M[bx]) {
      minn[bx] = min(M[ax], minn[bx]);
    } else {
      minn[ax] = min(M[bx], minn[ax]);
    }
  }
  int current = 0;
  long long res = 0;
  for (int i = n; i >= 1; --i) {
    if (i == n) {
      res += 1;
      current = n + 1;
      continue;
    }
    current = min(minn[a[i]], current);
    res += current - i;
  }
  cout << res << endl;
}
