#include<bits/stdc++.h>
#define pt putchar
using namespace std;
typedef long long ll;
int read();
void write(ll);
const int N=1e5+5;
int n,m;
int dt[N*2],val[N*2],*a,*b;
const ll INF=1e18;
int p[N];
ll pre[N],suf[N],sm[N];
ll solveem(){
ll ans=-INF,cur=0;
for(int i=1;i<=n;i++){
cur=max(cur,0ll);
cur+=a[i];
ans=max(ans,cur);
}
return ans;
}
ll solve(int f){
f=val[f];
ll cntb=0,sumb=0;
for(int i=1;i<=m;i++){
if(b[i]>f){
cntb++;sumb+=b[i];
}
}
if(cntb==0){
return -INF-1;
}
int z=0;
for(int i=1;i<=n;i++){
if(a[i]<=f){
p[++z]=i;
ll cur=pre[z]=0;
for(int j=i-1;a[j]>f&&j>=1;j--){
cur+=a[j];
pre[z]=max(pre[z],cur);
}
cur=suf[z]=0;
for(int j=i+1;a[j]>f&&j<=n;j++){
cur+=a[j];
suf[z]=max(suf[z],cur);
}
sm[z]=0;
if(z>1){
for(int j=i-1;a[j]>f;j--){
sm[z]+=a[j];
}
}
}
}
ll pans=-INF;
if(z<cntb){
return pans;
}
ll cur=0;
for(int i=2;i<=cntb-1;i++){
cur+=sm[i];
}
for(int i=1;i+cntb-1<=z;i++){
ll cur2=0;
for(int j=p[i];j<=p[cntb+i-1];j++){
if(a[j]>f){
cur2+=a[j];
}
}
cur+=sm[i+cntb-1]-sm[i];
//printf("%lld %lld\n",cur,cur2);
pans=max(pans,cur+pre[i]+suf[i+cntb-1]+sumb);
}
return pans;
}
int main(){
//freopen("2.in","r",stdin);
n=read();m=read();a=dt;b=dt+n;
for(int i=1;i<=n+m;i++){
val[i]=dt[i]=read();
}
val[0]=-1e9-9;
sort(val+1,val+1+n+m);
ll ans=solveem();
if(n<=5000){
for(int f=1;f<=n+m;f++){
ans=max(ans,solve(f));
//printf("%3d:%lld\n",f,solve(f));
}
}
else{
mt19937 rnd(time(0));
int l=1,r=n+m,m1,m2;
for(int i=20;i>=0;i--){
if(l+(1<<i)<=n+m){
if(solve(l+(1<<i))==-INF){
l+=1<<i;
}
}
if(r-(1<<i)>=1){
if(solve(r-(1<<i))==-INF-1){
r-=(1<<i);
}
}
}
l++;r--;
while(r-l+1>=min(1500,n+m)){
m1=(l*2+r)/3,m2=(l+r*2)/3;
ll v1=solve(m1),v2=solve(m2);
if(v1<v2){
l=m1+1;
}
else if(v1>v2){
r=m2-1;
}
else{
int u=1;
for(;u<=5;u++){
m1=rnd()%(r-l+1)+l;
m2=rnd()%(r-l+1)+l;
if(m1>m2){
swap(m1,m2);
}
v1=solve(m1),v2=solve(m2);
if(v1<v2){
l=m1+1;
}
else if(v1>v2){
r=m2-1;
}
else{
continue;
}
break;
}
if(u==5){
int o=(r-l+1)/5;
l+=o;r-=o;
}
}
}
for(int i=l;i<=r;i++){
ans=max(ans,solve(i));
}
}
write(ans);
return 0;
}
int read(){
int x=0,f=1;char c=getchar();
while(c<'0'||c>'9'){
if(c=='-'){
f=-1;
}
c=getchar();
}
while(c>='0'&&c<='9'){
x=x*10-'0'+c;
c=getchar();
}
return x*f;
}
void write(ll x){
if(x<0){
pt('-');
x=-x;
}
if(x>9){
write(x/10);
}
pt(x%10+'0');
}