#include <bits/stdc++.h>
using namespace std;
int64_t binarySearch(int64_t st, int64_t en, vector<int64_t> &ai,
                     vector<int64_t> &bi, int64_t n, int64_t k) {
  if (st > en) {
    return st - 1;
  }
  int64_t mid = st + (en - st) / 2, i;
  int64_t klocal = k;
  for (i = 0; i < n; i++) {
    int64_t req = mid * ai[i];
    if (bi[i] < req) {
      klocal -= (req - bi[i]);
    }
    if (klocal < 0) break;
  }
  if (klocal == 0) {
    return mid;
  }
  if (klocal >= 0) {
    return binarySearch(mid + 1, en, ai, bi, n, k);
  }
  return binarySearch(st, mid - 1, ai, bi, n, k);
}
int main() {
  int64_t n, k, i, minc;
  cin >> n >> k;
  vector<int64_t> ai(n), bi(n);
  for (i = 0; i < n; i++) {
    cin >> ai[i];
  }
  for (i = 0; i < n; i++) {
    cin >> bi[i];
  }
  minc = binarySearch(1, 2000000020, ai, bi, n, k);
  cout << minc << endl;
  return 0;
}
