#include <iostream>
#include <vector>
using namespace std;
void solve() {
int n, m, a[1002]={};
vector<int>v;
cin >> n >> m;
int x;
for (int i = 0; i < n; i++) {
cin >> x;
if (a[x] == 0) {
v.push_back(x);
}
a[x]++;
}
int sum = 0;
int z = v.size();
while (m--) {
cin >> x;
if (v[z-1] <= x) {
v.push_back(x);
z++;
a[x]++;
}
else {
for (int i = 0; i < z; i++) {
if (v[i] > x) {
sum += (z - i);
if (a[x] == 0) {
z++;
v.insert(v.begin() + i, x);
}
a[x]++;
break;
}
}
}
}
cout << sum;
}
int main() {
int t = 1;
//cin >> t;
while(t--){
solve();
}
}
Copy