#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int N=2e5+5;
ll n,m,a[N],b[N];
bool can(ll mid)
{
ll cur=a[0],o=0;
for(int i=1;i<n;i++)
{
if(cur+a[i]<=mid)
{
cur+=a[i];
}
else
{
while(o<m&&cur+a[i]>mid)
{
cur+=b[o];
o++;
}
cur=max(0LL,cur);
cur+=a[i];
if(cur>mid) return 0;
}
}
return cur<=mid;
}
signed main()
{
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
cin>>n>>m;
for(int i=0;i<n;i++)
{
cin>>a[i];
}
for(int o=0;o<m;o++)
{
cin>>b[o];
}
ll l=*max_element(a,a+n),r=1e17,ans=l;
while(l<=r)
{
ll mid=(l+r)/2;
if(can(mid))
{
ans=mid;
r=mid-1;
}
else
{
l=mid+1;
}
}
cout<<ans;
return 0;
}
I2luY2x1ZGU8Yml0cy9zdGRjKysuaD4KdXNpbmcgbmFtZXNwYWNlIHN0ZDsKI2RlZmluZSBsbCBsb25nIGxvbmcKY29uc3QgaW50IE49MmU1KzU7CmxsIG4sbSxhW05dLGJbTl07CmJvb2wgY2FuKGxsIG1pZCkKewogICAgbGwgY3VyPWFbMF0sbz0wOwogICAgZm9yKGludCBpPTE7aTxuO2krKykKICAgIHsKICAgICAgICBpZihjdXIrYVtpXTw9bWlkKQogICAgICAgIHsKICAgICAgICAgICAgY3VyKz1hW2ldOwogICAgICAgIH0KICAgICAgICBlbHNlCiAgICAgICAgewogICAgICAgICAgICB3aGlsZShvPG0mJmN1cithW2ldPm1pZCkKICAgICAgICAgICAgewogICAgICAgICAgICAgICAgY3VyKz1iW29dOwogICAgICAgICAgICAgICAgbysrOwogICAgICAgICAgICB9CiAgICAgICAgICAgIGN1cj1tYXgoMExMLGN1cik7CiAgICAgICAgICAgIGN1cis9YVtpXTsKICAgICAgICAgICAgaWYoY3VyPm1pZCkgcmV0dXJuIDA7CiAgICAgICAgfQogICAgfQogICAgcmV0dXJuIGN1cjw9bWlkOwp9CnNpZ25lZCBtYWluKCkKewogICAgaW9zX2Jhc2U6OnN5bmNfd2l0aF9zdGRpbygwKTtjaW4udGllKDApO2NvdXQudGllKDApOwogICAgY2luPj5uPj5tOwogICAgZm9yKGludCBpPTA7aTxuO2krKykKICAgIHsKICAgICAgICBjaW4+PmFbaV07CiAgICB9CiAgICBmb3IoaW50IG89MDtvPG07bysrKQogICAgewogICAgICAgIGNpbj4+YltvXTsKICAgIH0KICAgIGxsIGw9Km1heF9lbGVtZW50KGEsYStuKSxyPTFlMTcsYW5zPWw7CiAgICB3aGlsZShsPD1yKQogICAgewogICAgICAgIGxsIG1pZD0obCtyKS8yOwogICAgICAgIGlmKGNhbihtaWQpKQogICAgICAgIHsKICAgICAgICAgICAgYW5zPW1pZDsKICAgICAgICAgICAgcj1taWQtMTsKICAgICAgICB9CiAgICAgICAgZWxzZQogICAgICAgIHsKICAgICAgICAgICAgbD1taWQrMTsKICAgICAgICB9CiAgICB9CiAgICBjb3V0PDxhbnM7CiAgICByZXR1cm4gMDsKfQ==