#include <bits/stdc++.h>
using namespace std;
long long a, b = 2000000000, c, k, n;
long long x[100001], y[100001];
bool check(long long c) {
  long long am = 0;
  for (int i = 1; i <= n; i++) {
    if (y[i] < x[i] * c) am += x[i] * c - y[i];
    if (am > k) return false;
  }
  return true;
}
int main() {
  cin >> n >> k;
  for (int i = 1; i <= n; i++) cin >> x[i];
  for (int i = 1; i <= n; i++) cin >> y[i];
  while (a < b) {
    c = (a + b + 1) / 2;
    if (check(c))
      a = c;
    else
      b = c - 1;
  }
  cout << a << endl;
}
