#include <bits/stdc++.h>
using namespace std;
long long int arr[100005];
long long int brr[100005];
int main() {
  long long int n, i, k, lo, hi, ans, mid, tmp, t, sub;
  cin >> n >> k;
  for (i = 1; i <= n; i++) cin >> arr[i];
  for (i = 1; i <= n; i++) cin >> brr[i];
  ans = 0;
  lo = 0;
  hi = 10000000001;
  bool f;
  while (hi >= lo) {
    mid = hi + lo;
    mid = mid / 2;
    tmp = k;
    f = 1;
    for (i = 1; i <= n; i++) {
      t = arr[i] * mid;
      if (brr[i] >= t) {
      } else {
        sub = t - brr[i];
        if (tmp >= sub) {
          tmp -= sub;
        } else {
          f = 0;
        }
      }
      if (f == 0) break;
    }
    if (f) {
      lo = mid + 1;
      ans = max(ans, mid);
    } else {
      hi = mid - 1;
    }
  }
  cout << ans << endl;
}
