#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1000000007;
int n, k;
vector<int> v, b;
bool ch(int m) {
  long long add = 0;
  for (int i = 0; i < n; i++) {
    add += max((long long)m * v[i] - b[i], (long long)0);
    if (add > k) break;
  }
  return add <= k;
}
int main() {
  cin >> n >> k;
  v.resize(n);
  b.resize(n);
  for (int i = 0; i < n; i++) scanf("%d", &v[i]);
  for (int i = 0; i < n; i++) scanf("%d", &b[i]);
  long long l = 0, r = 2e9;
  long long ans = 0;
  while (l <= r) {
    long long mid = (l + r) / 2;
    if (ch(mid)) {
      ans = max(ans, mid);
      l = mid + 1;
    } else
      r = mid - 1;
  }
  cout << l - 1 << endl;
  return 0;
}
