#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long ll;
bool check(ll X, int N, ll M, const vector<ll>& A, const vector<ll>& B) {
ll total_slots_needed = 0;
ll total_slots_available = N * M;
for (int i = 0; i < N; ++i) {
ll best_gain = max(A[i], B[i]);
ll slots_used = 0;
if (X <= M * best_gain) {
// Can reach target using only a portion of its own M slots
slots_used = (X + best_gain - 1) / best_gain;
} else {
// Must use all M own slots + extra slots from other courses
ll remaining_needed = X - (M * best_gain);
slots_used = M + (remaining_needed + B[i] - 1) / B[i];
}
total_slots_needed += slots_used;
// Optimization: Early exit if we already exceeded total available slots
if (total_slots_needed > total_slots_available) return false;
}
return total_slots_needed <= total_slots_available;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int N;
ll M;
if (!(cin >> N >> M)) return 0;
vector<ll> A(N), B(N);
for (int i = 0; i < N; ++i) cin >> A[i];
for (int i = 0; i < N; ++i) cin >> B[i];
ll low = 0, high = 2e18; // Sufficiently large upper bound
ll ans = 0;
while (low <= high) {
ll mid = low + (high - low) / 2;
if (check(mid, N, M, A, B)) {
ans = mid;
low = mid + 1;
} else {
high = mid - 1;
}
}
cout << ans << endl;
return 0;
}