#include <bits/stdc++.h>
using namespace std;
int n, m;
int x, y;
int v[300010], mp[300010];
int d[300010];
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    cin >> v[i];
    mp[v[i]] = i;
    d[i] = -1;
  }
  for (int i = 1; i <= m; i++) {
    cin >> x >> y;
    int a = mp[x];
    int b = mp[y];
    if (a > b) swap(a, b);
    d[b] = max(d[b], a);
  }
  cout << "\n";
  long long ans = 0;
  int l_r = 0;
  for (int i = 1; i <= n; i++) {
    l_r = max(d[i], l_r);
    ans += i - l_r;
  }
  cout << ans << "\n";
}
