//============================================================================
// Name : mmmmmmmm.cpp
// Author : sameh mohamed
// Copyright : don't try i'm warnning you......
// Description : Hello World
//============================================================================
//Egypt came then History
//Pharoas were coders but using different compilers{}{}{}{}{}}}}{{{{@#$%^^&&$$$###()()(***)))([][][][][]]][
#include<bits/stdc++.h>
#include <iostream>
#include<string>
#include<algorithm>
#include<set>
#include<vector>
#include<map>
#include<cmath>
using namespace std;
int b[1005]={0};
int main()
{
int n,m;
cin>>n>>m;
vector<int>a;
for(int i=0;i<n;i++)
{
int v;
cin>>v;
if(b[v]==0)
a.push_back(v);
b[v]++;
}
int c=0;
while(m--)
{
int v;
cin>>v;
if(v>=a.back()&&b[v]==0)
{a.push_back(v);
b[v]++;}
else
{
for(int i=0;i<(int)a.size();i++)
{
if(a[i]>v)
{
c+=a.size()-i;
if(b[v]==0)
{a.push_back(v);
sort(a.begin(),a.end());}
break;
}
}
}
}
cout<<c;
return 0;
}
Copy