#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, k, a[1000001], b[1000001];
  cin >> n >> k;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  for (int i = 0; i < n; i++) {
    cin >> b[i];
  }
  long long low = 0, high = 2e9, mid, answer = 0;
  while (low <= high) {
    mid = (high + low) / 2;
    long long magic = k;
    for (int i = 0; i < n; i++) {
      if (b[i] / a[i] >= mid) {
        continue;
      }
      long long need = (long long)mid * a[i];
      magic -= need - b[i];
      if (magic < 0) break;
    }
    if (magic < 0) {
      high = mid - 1;
    } else {
      (answer = mid);
      low = mid + 1;
    }
  }
  cout << answer << endl;
  return 0;
}
