#include <bits/stdc++.h>
using namespace std;
int a[1010101];
int b[1010101];
int ss[1010101];
int n, m;
struct cmp {
  bool operator()(const int i, const int j) { return a[i] < a[j]; }
};
struct node {
  int l, r;
  int ind;
  int sl, sr;
} pp[1010101];
bool cmp1(const node &a, const node &b) { return a.l < b.l; }
bool cmp2(const node &a, const node &b) { return a.r < b.r; }
int c[1010101];
void update(int pos, int val) {
  while (pos <= n) {
    c[pos] += val;
    pos += ((pos) & (-(pos)));
  }
}
int req(int pos) {
  int ans = 0;
  while (pos > 0) {
    ans += c[pos];
    pos -= ((pos) & (-(pos)));
  }
  return ans;
}
priority_queue<int, vector<int>, cmp> q;
int main(void) {
  while (EOF != scanf("%d%d", &n, &m)) {
    for (int i = (1); i <= (n); i++) scanf("%d", a + i), pp[i].ind = i;
    for (int i = (1); i <= (m); i++) scanf("%d", b + i);
    int tt = 1;
    for (int i = (1); i <= (n); i++) {
      if (a[i] == b[tt]) {
        tt++;
        ss[i] = 1;
      } else
        ss[i] = 0;
    }
    for (int i = (1); i <= (n); i++) {
      if (ss[i] == 1) {
        while ((!q.empty()) && a[i] < a[q.top()]) {
          pp[q.top()].r = i;
          q.pop();
        }
      } else {
        q.push(i);
      }
    }
    while (!q.empty()) {
      pp[q.top()].r = n + 1;
      q.pop();
    }
    for (int i = (n); i >= (1); i--) {
      if (ss[i] == 1) {
        while ((!q.empty()) && a[i] < a[q.top()]) {
          pp[q.top()].l = i;
          q.pop();
        }
      } else {
        q.push(i);
      }
    }
    while (!q.empty()) {
      pp[q.top()].l = 0;
      q.pop();
    }
    sort(pp + 1, pp + n + 1, cmp1);
    tt = 0;
    memset(c, 0, sizeof(c));
    for (int i = (1); i <= (n); i++) {
      while (pp[i].l > tt) {
        tt++;
        update(a[tt], 1);
      }
      pp[i].sl = req(a[pp[i].ind]);
    }
    memset(c, 0, sizeof(c));
    sort(pp + 1, pp + n + 1, cmp2);
    tt = 0;
    for (int i = (1); i <= (n); i++) {
      while (pp[i].r - 1 > tt) {
        tt++;
        update(a[tt], 1);
      }
      pp[i].sr = req(a[pp[i].ind]) - 1;
    }
    long long ans = 0;
    for (int i = (1); i <= (n); i++) {
      if (!ss[pp[i].ind]) {
        ans += (pp[i].r - pp[i].l - 1 + pp[i].sl - pp[i].sr);
      }
    }
    printf("%I64d\n", ans);
  }
  return 0;
}
