#include <bits/stdc++.h>
using namespace std;
int p[2000000];
int b[2000000];
int sta[2000000];
int u[2000000];
int poz[2000000];
int pozz[2000000];
int low[2000000];
int high[2000000];
int fen[2000000];
int next_[2000000];
int pr[2000000];
void up(int v, int t) {
  while (v <= 1000000) {
    fen[v] += t;
    v = (v | (v + 1));
  }
}
int get(int v) {
  int ans = 0;
  while (v > 0) {
    ans += fen[v];
    v = (v & (v + 1)) - 1;
  }
  return ans;
}
int main() {
  int n, k;
  cin >> n >> k;
  for (int i = 1; i <= n; i++) scanf("%d", &p[i]);
  for (int i = 1; i <= k; i++) {
    scanf("%d", &b[i]);
    u[b[i]] = 1;
  }
  int st = 0;
  for (int i = 1; i <= n; i++) {
    if (!u[p[i]]) {
      int ll = 0;
      int rr = st + 1;
      while (ll + 1 < rr) {
        int cc = (ll + rr) / 2;
        if (sta[cc] < p[i])
          ll = cc;
        else
          rr = cc;
      }
      low[i] = poz[ll] + 1;
    } else {
      while (st > 0) {
        if (sta[st] >= p[i])
          st--;
        else
          break;
      }
      st++;
      sta[st] = p[i];
      poz[st] = i;
    }
  }
  st = 0;
  poz[0] = n + 1;
  long long ans = 0, cc = 0;
  for (int i = n; i >= 1; i--) {
    if (!u[p[i]]) {
      int ll = 0;
      int rr = st + 1;
      while (ll + 1 < rr) {
        int cc = (ll + rr) / 2;
        if (sta[cc] < p[i])
          ll = cc;
        else
          rr = cc;
      }
      high[i] = poz[ll] - 1;
    } else {
      while (st > 0) {
        if (sta[st] >= p[i])
          st--;
        else
          break;
      }
      st++;
      sta[st] = p[i];
      poz[st] = i;
    }
    if (!u[p[i]]) {
      cc++;
      pozz[cc] = i;
      next_[cc] = pr[high[i]];
      pr[high[i]] = cc;
      ans += (long long)(high[i] - low[i] + 1);
    }
  }
  for (int i = 1; i <= n; i++) {
    int j = pr[i - 1];
    while (j > 0) {
      up(pozz[j], -1);
      j = next_[j];
    }
    if (!u[p[i]]) {
      ans -= (long long)(get(n) - get(low[i] - 1));
      up(i, 1);
    }
  }
  cout << ans << endl;
  return 0;
}
