#include <bits/stdc++.h>
using namespace std;
const long long inf = 1e18;
const long long mod = 1e17 + 7;
const long long N = 1e5 + 5;
long long a[N], b[N], n, k;
int main() {
  ios_base::sync_with_stdio(false);
  cin >> n >> k;
  for (long long i = 0; i < (n); ++i) cin >> a[i];
  for (long long i = 0; i < (n); ++i) cin >> b[i];
  long long mx = 0, beg = 0, en = 2e9 + 5, mid;
  while (beg < en) {
    mid = (beg + en) / 2;
    long long c = 0;
    for (long long i = 0; i < (n); ++i) {
      c += max(a[i] * mid - b[i], 0LL);
      if (c > k) break;
    }
    if (c <= k) {
      beg = mid + 1;
      mx = max(mx, mid);
    } else
      en = mid;
  }
  cout << mx << endl;
}
