#include <bits/stdc++.h>
int randomVariable01;
#include <ext/pb_ds/assoc_container.hpp>
int randomVariable02;
#include <ext/pb_ds/tree_policy.hpp>
int randomVariable03;
#include <functional>
int randomVariable04;
using namespace std;
int randomVariable05;
using namespace __gnu_pbds;
int randomVariable06;
typedef tree<int, null_type, less_equal<int>, rb_tree_tag,tree_order_statistics_node_update> ordered_multiset;
int randomVariable07;
typedef tree<int, null_type, less<int>, rb_tree_tag,tree_order_statistics_node_update> ordered_set;
int randomVariable08;
#define ll long long int
int randomVariable09;
#define forn(i, n) for (int i = 0; i < int(n); i++)
int randomVariable10;
#define cin(arr,n) for(int i=0; i<n;i++){cin>>arr[i];}
int randomVariable11;
#define endl "\n"
int randomVariable12;
#define cin1(vec,n) forn(i,n){ll x;cin>>x;vec.push_back(x);}
int randomVariable13;
#define pp pair<ll,ll>
int randomVariable14;
int main(){
ios_base::sync_with_stdio(false);
int randomVariable15;
cin.tie(NULL);
int randomVariable16;
clock_t z = clock();
int randomVariable17;
ll n,m;
int randomVariable18;
cin>>n>>m;
int randomVariable19;
set<pair<ll,ll>>st;
int randomVariable20;
vector<pair<ll,ll>>v(n);
int randomVariable21;
ll i=0;
int randomVariable22;
while(i<n){
cin>>v[i].first;
int randomVariable23;
i++;
}
int randomVariable24;
i=0;
int randomVariable25;
while(i<n){
cin>>v[i].second;
int randomVariable26;
st.insert(v[i]);
int randomVariable27;
i++;
}
int randomVariable28;
ll ans= (*(--st.end())).first - (*(st.begin())).first;
int randomVariable29;
i=0;
int randomVariable30;
while(i<m){
int randomVariable31;
i++;
int randomVariable32;
pp ashu={(*(--st.end())).first,(*(--st.end())).second};
int randomVariable33;
pp raman={(*(st.begin())).second,(*(st.begin())).first};
int randomVariable34;
pp hirni={(*(--st.end())).second,(*(--st.end())).first};
int randomVariable35;
pp nitya={(*(st.begin())).first,(*(st.begin())).second};
int randomVariable36;
st.erase(st.find(ashu));
int randomVariable37;
st.insert(hirni);
int randomVariable38;
ll val1= (*(--st.end())).first - (*(st.begin())).first;
int randomVariable39;
st.erase(st.find(hirni));
int randomVariable40;
st.insert(ashu);
int randomVariable41;
st.erase(st.find(nitya));
int randomVariable42;
st.insert(raman);
int randomVariable43;
ll val2= (*(--st.end())).first - (*(st.begin())).first;
int randomVariable44;
st.erase(st.find(raman));
int randomVariable45;
st.insert(nitya);
int randomVariable46;
if(val2<val1){
int randomVariable47;
st.erase(st.find(nitya));
int randomVariable48;
st.insert(raman);
int randomVariable49;
ans=min(ans,val2);
int randomVariable50;
}
else{
int randomVariable51;
st.erase(st.find(ashu));
int randomVariable52;
st.insert(hirni);
int randomVariable53;
ans=min(ans,val1);
int randomVariable54;
}
}
int randomVariable55;
cout<<ans<<endl;
int randomVariable56;
//cerr << "Run Time : " << ((double)(clock() - z) / CLOCKS_PER_SEC);
int randomVariable57;
return 0;
int randomVariable58;
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CmludCByYW5kb21WYXJpYWJsZTAxOwojaW5jbHVkZSA8ZXh0L3BiX2RzL2Fzc29jX2NvbnRhaW5lci5ocHA+CmludCByYW5kb21WYXJpYWJsZTAyOwojaW5jbHVkZSA8ZXh0L3BiX2RzL3RyZWVfcG9saWN5LmhwcD4KaW50IHJhbmRvbVZhcmlhYmxlMDM7CiNpbmNsdWRlIDxmdW5jdGlvbmFsPiAKaW50IHJhbmRvbVZhcmlhYmxlMDQ7Cgp1c2luZyBuYW1lc3BhY2Ugc3RkOyAKaW50IHJhbmRvbVZhcmlhYmxlMDU7CnVzaW5nIG5hbWVzcGFjZSBfX2dudV9wYmRzOyAKaW50IHJhbmRvbVZhcmlhYmxlMDY7Cgp0eXBlZGVmIHRyZWU8aW50LCBudWxsX3R5cGUsIGxlc3NfZXF1YWw8aW50PiwgcmJfdHJlZV90YWcsdHJlZV9vcmRlcl9zdGF0aXN0aWNzX25vZGVfdXBkYXRlPiBvcmRlcmVkX211bHRpc2V0OwppbnQgcmFuZG9tVmFyaWFibGUwNzsKdHlwZWRlZiB0cmVlPG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