#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 5;
int n, m, a[N], b[N];
int segMax[1 << 21], segMin[1 << 21], cnt[1 << 21];
bool delet[N];
void updateMax(int i, int v, int ni = 0, int ns = 0, int ne = n) {
  if (ns > i || ne < i || ns > ne) return;
  if (ns == ne) {
    if (ns == i) segMax[ni] = v;
    return;
  }
  int l = ni * 2 + 1, r = l + 1, mid = (ns + ne) / 2;
  updateMax(i, v, l, ns, mid);
  updateMax(i, v, r, mid + 1, ne);
  segMax[ni] = max(segMax[l], segMax[r]);
}
int mx(int qs, int qe, int ni = 0, int ns = 0, int ne = n) {
  if (ns > qe || ne < qs || ns > ne) return -1;
  if (ns >= qs && ne <= qe) return segMax[ni];
  int l = ni * 2 + 1, r = l + 1, mid = (ns + ne) / 2;
  return max(mx(qs, qe, l, ns, mid), mx(qs, qe, r, mid + 1, ne));
}
void updateMin(int i, int v, int ni = 0, int ns = 0, int ne = n) {
  if (ns > i || ne < i || ns > ne) return;
  if (ns == ne) {
    if (ns == i) segMin[ni] = v;
    return;
  }
  int l = ni * 2 + 1, r = l + 1, mid = (ns + ne) / 2;
  updateMin(i, v, l, ns, mid);
  updateMin(i, v, r, mid + 1, ne);
  segMin[ni] = min(segMin[l], segMin[r]);
}
int mn(int qs, int qe, int ni = 0, int ns = 0, int ne = n) {
  if (ns > qe || ne < qs || ns > ne) return 1e9;
  if (ns >= qs && ne <= qe) return segMin[ni];
  int l = ni * 2 + 1, r = l + 1, mid = (ns + ne) / 2;
  return min(mn(qs, qe, l, ns, mid), mn(qs, qe, r, mid + 1, ne));
}
void update(int i, int v, int ni = 0, int ns = 0, int ne = n) {
  if (ns > i || ne < i || ns > ne) return;
  if (ns == ne) {
    if (ns == i) cnt[ni] = v;
    return;
  }
  int l = ni * 2 + 1, r = l + 1, mid = (ns + ne) / 2;
  update(i, v, l, ns, mid);
  update(i, v, r, mid + 1, ne);
  cnt[ni] = cnt[l] + cnt[r];
}
int query(int qs, int qe, int ni = 0, int ns = 0, int ne = n) {
  if (ns > qe || ne < qs || ns > ne) return 0;
  if (ns >= qs && ne <= qe) return cnt[ni];
  int l = ni * 2 + 1, r = l + 1, mid = (ns + ne) / 2;
  return query(qs, qe, l, ns, mid) + query(qs, qe, r, mid + 1, ne);
}
void prep() {
  int i = 0, j = 0;
  while (j < m) {
    if (a[i] == b[j])
      ++i, ++j;
    else
      delet[i++] = 1;
  }
  while (i < n) delet[i++] = 1;
}
void build(int ni = 0, int ns = 0, int ne = n) {
  if (ns == ne) {
    segMax[ni] = -1e9;
    segMin[ni] = 1e9;
    cnt[ni] = 1;
  }
  if (ns >= ne) return;
  int l = ni * 2 + 1, r = l + 1, mid = (ns + ne) / 2;
  build(l, ns, mid);
  build(r, mid + 1, ne);
  segMax[ni] = -1e9;
  segMin[ni] = 1e9;
  cnt[ni] = cnt[l] + cnt[r];
}
int l[N], r[N];
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 0; i < n; ++i) scanf("%d", a + i);
  for (int i = 0; i < m; ++i) scanf("%d", b + i);
  prep();
  build();
  int mnn = 1e9;
  for (int i = 0; i < n; ++i) {
    if (!delet[i]) {
      updateMax(a[i], i);
      mnn = min(mnn, a[i]);
      continue;
    }
    if (mnn >= a[i])
      l[i] = 0;
    else
      l[i] = mx(0, a[i] - 1) + 1;
  }
  mnn = 1e9;
  for (int i = n - 1; i >= 0; --i) {
    if (!delet[i]) {
      updateMin(a[i], i);
      mnn = min(mnn, a[i]);
      continue;
    }
    if (mnn >= a[i])
      r[i] = n - 1;
    else
      r[i] = mn(0, a[i] - 1) - 1;
  }
  long long ans = 0;
  vector<int> idx;
  for (int i = 0; i < n; ++i) {
    if (delet[i]) idx.push_back(i);
  }
  sort(idx.begin(), idx.end(), [](int i, int j) { return a[i] < a[j]; });
  for (int i : idx) {
    ans += query(l[i], r[i]);
    update(i, 0);
  }
  printf("%lld", ans);
  return 0;
}
