#include <bits/stdc++.h>
#pragma GCC diagnostic ignored "-Wwrite-strings"
using namespace std;
template <class T, class U>
ostream &operator<<(ostream &out, const pair<T, U> &A) {
  out << A.first << "_" << A.second;
  return out;
}
template <template <typename, typename> class ContainerT, typename ValueT>
ostream &operator<<(ostream &out,
                    const ContainerT<ValueT, std::allocator<ValueT> > &A) {
  for (__typeof((A).begin()) i = (A).begin(); i != (A).end(); ++i)
    out << *i << " ";
  return out;
}
template <template <typename, typename> class ContainerT, typename ValueT,
          typename ValueU>
ostream &operator<<(
    ostream &out, const ContainerT<pair<ValueT, ValueU>,
                                   std::allocator<pair<ValueT, ValueU> > > &A) {
  for (__typeof((A).begin()) i = (A).begin(); i != (A).end(); ++i)
    out << *i << " ";
  return out;
}
template <class T>
void mini(T &a, const T &b) {
  if (b < a) a = b;
}
template <class T>
void maxi(T &a, const T &b) {
  if (b > a) a = b;
}
bool myComp(const pair<int, int> &a, const pair<int, int> &b) {
  return a.first < b.first;
}
int N, K;
long long solve__() {
  cin >> N >> K;
  vector<int> A(N);
  for (int i = 0; i < (N); ++i) cin >> A[i];
  vector<int> B(K);
  for (int i = 0; i < (K); ++i) cin >> B[i];
  vector<pair<int, int> > C(N - K + 100, make_pair(-1, -1));
  set<pair<int, int> > A_;
  for (int i = 0; i < (N); ++i) A_.insert(make_pair(A[i], i));
  set<pair<int, int> > B_;
  for (int i = 0; i < (K); ++i) B_.insert(make_pair(B[i], -1));
  C.resize(set_difference((A_).begin(), (A_).end(), (B_).begin(), (B_).end(),
                          C.begin(), myComp) -
           C.begin());
  cout << "C"
       << ": " << C << endl;
  ;
  assert(C.back() != make_pair(-1, -1));
  int ans = 0;
  vector<bool> chk(N, true);
  for (int i = 0; i < (N - K); ++i) {
    int val = C[i].first;
    int idx = C[i].second;
    int l = idx, r = idx;
    assert(A[idx] == val);
    while (l and (not chk[l - 1] or A[l - 1] >= val)) {
      l--;
      ans += chk[l];
    }
    while (r < A.size() and (not chk[r] or A[r] >= val)) {
      ans += chk[r];
      r++;
    }
    assert(chk[idx]);
    chk[idx] = false;
  }
  return ans;
}
const int X = 1000000;
struct indexTree {
  vector<int> tree;
  int n;
  void init(int sz) {
    for (n = 1; n < sz; n <<= 1)
      ;
    tree.resize(n * 2, 0);
  }
  void insert(int v) {
    int l, r, m, c;
    l = 0, r = n - 1, c = 0;
    while (l < r) {
      tree[c]++;
      m = (l + r) / 2;
      if (v <= m) {
        c = c * 2 + 1;
        r = m;
      } else {
        c = c * 2 + 2;
        l = m + 1;
      }
    }
    tree[c]++;
  }
  void erase(int v) {
    int l, r, m, c;
    l = 0, r = n - 1, c = 0;
    while (l < r) {
      tree[c]--;
      m = (l + r) / 2;
      if (v <= m) {
        c = c * 2 + 1;
        r = m;
      } else {
        c = c * 2 + 2;
        l = m + 1;
      }
    }
    tree[c]--;
  }
  int sum(int v) {
    int l, r, m, c, h;
    l = 0, r = n - 1, c = 0, h = 0;
    while (l <= r && l <= v) {
      if (r == v) {
        h += tree[c];
        break;
      }
      m = (l + r) / 2;
      if (v <= m) {
        c = c * 2 + 1;
        r = m;
      } else {
        h += tree[c * 2 + 1];
        c = c * 2 + 2;
        l = m + 1;
      }
    }
    return h;
  }
  int find(int v) {
    int l, r, m, c;
    l = 0, r = n - 1, c = 0;
    while (l < r) {
      m = (l + r) / 2;
      if (v <= tree[c * 2 + 1]) {
        c = c * 2 + 1;
        r = m;
      } else {
        v -= tree[c * 2 + 1];
        c = c * 2 + 2;
        l = m + 1;
      }
    }
    return l;
  }
};
const int MAX_N = X + 5;
int pos[MAX_N], used[MAX_N];
int A[MAX_N], B[MAX_N];
int tr[MAX_N];
void insert(int p) {
  while (p < MAX_N) {
    tr[p]++;
    p += p & -p;
  }
}
int getsum(int p) {
  if (p < 0) return 0;
  int ret = 0;
  while (p) {
    ret += tr[p];
    p -= p & -p;
  }
  return ret;
}
int getsum(int l, int r) { return getsum(r) - getsum(l); };
long long solve() {
  long long ans = 0;
  cin >> N >> K;
  memset(pos, -1, sizeof(pos));
  memset(used, 0, sizeof(used));
  for (int i = 0; i < (N); ++i) scanf("%d", A + i);
  for (int i = 0; i < (K); ++i) scanf("%d", B + i);
  for (int i = 0; i < (N); ++i) pos[A[i]] = i;
  for (int i = 0; i < (K); ++i) used[B[i]] = true;
  set<int> used_;
  memset(tr, 0, sizeof(tr));
  indexTree T;
  T.init(X + 1);
  used_.insert(-1);
  used_.insert(N);
  for (int i = (1); i <= (X); ++i) {
    if (pos[i] == -1)
      continue;
    else if (used[i] == true)
      used_.insert(pos[i]);
    else {
      int l = *--used_.upper_bound(pos[i]), r = *used_.upper_bound(pos[i]);
      assert(l == -1 or A[l] < i);
      assert(r == N or A[r] < i);
      ans += r - l - 1;
      ans -= T.sum(r);
      ans += T.sum(l);
      T.insert(pos[i]);
    }
  }
  return ans;
}
int main() {
  cout << solve() << endl;
  return 0;
}
