#include <bits/stdc++.h>
using namespace std;
vector<long long> com;
vector<long long> all;
long long c, a, n, k, mm;
void solve() {
  long long s = 0, e = (long long)1e9 * 2 + 5;
  long long mid = 0;
  long long sum = 0;
  while (s <= e) {
    mid = (s + e) / 2;
    for (int i = 0; i < n; i++) {
      sum += max((long long)0, (com[i] * mid - all[i]));
      if (sum > (long long)1e18) {
        sum = k + 1;
        break;
      }
    }
    if (sum <= k) {
      mm = mid;
      s = mid + 1;
    } else
      e = mid - 1;
    sum = 0;
  }
  cout << mm;
}
int main() {
  cin >> n >> k;
  for (int i = 0; i < n; i++) {
    cin >> c;
    com.push_back(c);
  }
  for (int i = 0; i < n; i++) {
    cin >> a;
    all.push_back(a);
  }
  solve();
  return 0;
}
