#include <bits/stdc++.h>
using namespace std;
int n, k;
int a[100005];
int b[100005];
bool ok(long long x) {
  long long s = k;
  for (int i = 0; i < n; i++) {
    if (x * a[i] >= b[i]) {
      s -= (x * a[i] - b[i]);
    }
    if (s < 0) {
      return false;
    }
  }
  return true;
}
int main() {
  cin >> n >> k;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  for (int j = 0; j < n; j++) {
    cin >> b[j];
  }
  if (n == 1) {
    cout << (b[0] + k) / a[0] << endl;
  } else {
    int sum = 0;
    long long l = 0, r = 0xffffffff;
    long long mid;
    while (l <= r) {
      mid = (l + r) >> 1;
      if (ok(mid)) {
        l = mid + 1;
        sum = mid;
      } else {
        r = mid - 1;
      }
    }
    cout << sum << endl;
  }
  return 0;
}
