#include<stdio.h>
#include<iostream>
#include<algorithm>
using namespace std;
const int N=100005;
struct node
{
int a,id;
}p[N];
int n,m,x,a[N],t[N];
long long ans;
inline void read(int &v){
char ch,fu=0;
for(ch=‘*‘; (ch<‘0‘||ch>‘9‘)&&ch!=‘-‘; ch=getchar());
if(ch==‘-‘) fu=1, ch=getchar();
for(v=0; ch>=‘0‘&&ch<=‘9‘; ch=getchar()) v=v*10+ch-‘0‘;
if(fu) v=-v;
}
int solve(int x)
{
int ans=0;
while(x)
{
ans+=t[x];
x-=x&-x;
}
return ans;
}
void update(int x,int y)
{
while(x<=n+m)
{
t[x]+=y;
x+=x&-x;
}
}
bool cmp(const node&x,const node&y)
{
return x.a>y.a;
}
int main()
{
scanf("%d%d",&n,&m);
for(int i=n;i>=1;i--) read(p[i].a),p[i].id=i;
for(int i=n+1;i<=n+m;i++) read(p[i].a),p[i].id=i;
sort(p+1,p+n+m+1,cmp);
for(int i=1;i<=n+m;i++) update(i,1);
x=n;
for(int i=1;i<=n+m;i++)
{
if(p[i].id>x) ans+=solve(p[i].id-1)-solve(x);else
ans+=solve(x)-solve(p[i].id);
update(p[i].id,-1);
x=p[i].id;
}
cout<<ans;
return 0;
}