#include<bits/stdc++.h>
using namespace std;
#define ll long long
const ll nx = 3e5+5;
ll n,m,a[nx],b[nx];
bool check(ll x)
{
ll timeLeft = n*m;
for(int i = 1; i <= n; i++)
{
if(timeLeft < 0) return false;
ll total = 0;
if(a[i]>b[i])
{
ll cnt = x/a[i] + (x%a[i]!=0);
total += min(cnt*a[i],m*a[i]);
timeLeft -= min(m,cnt);
}
if(total>=x) continue;
ll cnt = (x-total)/b[i] + ((x-total)%b[i]!=0);
timeLeft -= cnt;
}
return timeLeft >= 0;
}
int main()
{
ios::sync_with_stdio(false); cin.tie(0);
cin>>n>>m;
for(int i = 1; i <= n; i++) cin>>a[i];
for(int i = 1; i <= n; i++) cin>>b[i];
ll l = 0, r = 1e18+5;
while(l<r)
{
ll md = (l+r+1)/2;
if(check(md)) l = md;
else r = md-1;
}
cout<<l;
}