#include <bits/stdc++.h>
using namespace std;
long long n, k;
vector<long long> a, b;
bool func(long long x) {
  int i, k1 = k;
  for (i = 0; i < n; i++) {
    if (b[i] / a[i] < x) {
      k -= x * a[i] - b[i];
      if (k < 0) {
        k = k1;
        return false;
      }
    }
  }
  k = k1;
  return true;
}
int main() {
  long long i, j, l = 1000000007, r = -1;
  cin >> n >> k;
  for (i = 0; i < n; i++) cin >> j, a.push_back(j);
  for (i = 0; i < n; i++)
    cin >> j, b.push_back(j), l = min(l, j / a[i]), r = max(r, j / a[i]);
  r += k + 1;
  while (l + 1 < r) {
    long long mid = l + (r - l) / 2;
    if (func(mid))
      l = mid;
    else
      r = mid;
  }
  cout << l;
  return 0;
}
