#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ii = pair<int, int>;
ll solve(int N, const vector<int>& xs, const set<ii>& ps) {
  vector<int> ys(N + 1, 0), zs(N + 1, 0);
  for (int i = 1; i <= N; ++i) {
    ys[xs[i]] = i;
  }
  for (auto p : ps) {
    auto x = p.first, y = p.second;
    auto a = ys[x], b = ys[y];
    auto i = min(a, b), j = max(a, b);
    zs[j] = max(zs[j], i);
  }
  ll ans = 0;
  int last = 0;
  for (int i = 1; i <= N; ++i) {
    if (zs[i]) last = max(last, zs[i]);
    ans += (i - last);
  }
  return ans;
}
int main() {
  ios::sync_with_stdio(false);
  int N, M;
  cin >> N >> M;
  vector<int> xs(N + 1);
  for (int i = 1; i <= N; ++i) cin >> xs[i];
  set<ii> ps;
  while (M--) {
    int a, b;
    cin >> a >> b;
    ps.insert(ii(min(a, b), max(a, b)));
  }
  auto ans = solve(N, xs, ps);
  cout << ans << '\n';
  return 0;
}
