#include <bits/stdc++.h>
using namespace std;
const double eps = 1e-6;
long long pw(long long b, long long p) {
  if (!p) return 1;
  long long sq = pw(b, p / 2);
  sq *= sq;
  if (p % 2) sq *= b;
  return sq;
}
int n;
long long cost_of_one[100100], units[100100];
bool OK(long long needed, int magic) {
  for (int i = 0; i < n; ++i) {
    if ((cost_of_one[i] * 1LL * needed) <= units[i])
      continue;
    else {
      if (magic >= ((cost_of_one[i] * 1LL * needed) - units[i]))
        magic -= ((cost_of_one[i] * 1LL * needed) - units[i]);
      else
        return 0;
    }
  }
  return 1;
}
int main() {
  int magic;
  cin >> n >> magic;
  for (int i = 0; i < n; ++i) {
    cin >> cost_of_one[i];
  }
  for (int i = 0; i < n; ++i) {
    cin >> units[i];
  }
  long long l = 0, mid, r = 1e9 * 2 + 1;
  while (l < r) {
    mid = l + (r - l + 1) / 2;
    if (OK(mid, magic))
      l = mid;
    else
      r = mid - 1;
  }
  cout << r << endl;
  return 0;
}
