#include <bits/stdc++.h>
using namespace std;
long long lo = 0, hi = 2000000000, mid, n, magic;
long long int a[100003], b[100003];
bool ok(int x) {
  long long int k = magic, test;
  for (int i = 0; i < n; i++) {
    test = x * a[i] - b[i];
    if (test > 0) {
      k -= test;
      if (k < 0) return false;
    }
  }
  return true;
}
int binarySearch() {
  while (lo < hi) {
    mid = (lo + hi + 1) / 2;
    if (ok(mid))
      lo = mid;
    else
      hi = mid - 1;
  }
  return lo;
}
int main() {
  cin >> n >> magic;
  for (int i = 0; i < n; i++) cin >> a[i];
  for (int i = 0; i < n; i++) cin >> b[i];
  cout << binarySearch();
  return 0;
}
