#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
void solve() {
  long long int n, k;
  long long int right = (long long int)2e9;
  long long int left = 0;
  cin >> n >> k;
  long long int a[n], b[n];
  for (int i = 0; i < n; i++) cin >> a[i];
  for (int i = 0; i < n; i++) cin >> b[i];
  while (right - left > 0) {
    long long int mid = (right + left + 1) / 2;
    long long int cnt = 0;
    for (int i = 0; i < n; i++) {
      cnt += max(0LL, mid * a[i] - b[i]);
      if (cnt > k) break;
    }
    if (cnt <= k)
      left = mid;
    else
      right = mid - 1;
  }
  cout << left;
}
int main() {
  solve();
  cout << "\n";
  return 0;
}
