#include <bits/stdc++.h>
using namespace std;
int n, a[100009], b[100009], k;
bool ok(long long x) {
  long long p = k;
  for (int i = 1; i <= n; i++)
    if (b[i] < a[i] * x) {
      p -= (a[i] * x - b[i]);
      if (p < 0) return 0;
    }
  return 1;
}
int main() {
  cin >> n >> k;
  for (int i = 1; i <= n; i++) cin >> a[i];
  for (int i = 1; i <= n; i++) cin >> b[i];
  long long l = 0, r = 2e9, g;
  while (l < r) {
    g = (l + r + 1) / 2;
    if (ok(g))
      l = g;
    else
      r = g - 1;
  }
  cout << l;
}
