#include <bits/stdc++.h>
using namespace std;
bool fun(vector<long long>& a, vector<long long>& b, long long ans,
         long long k) {
  for (int i = 0; i < a.size(); i++) {
    if (b[i] / a[i] >= ans)
      continue;
    else {
      long long temp = ans * a[i] - b[i];
      if (temp <= k) {
        k -= temp;
        continue;
      } else
        return false;
    }
  }
  return true;
}
int main() {
  int n;
  long long k;
  cin >> n >> k;
  vector<long long> a(n), b(n);
  for (int i = 0; i < n; i++) cin >> a[i];
  for (int i = 0; i < n; i++) cin >> b[i];
  long long maxx = 0, sum = 0;
  for (int i = 0; i < n; i++) {
    sum += a[i];
    maxx = max(b[i] / a[i], maxx);
  }
  long long low = 0, high = maxx + k / sum;
  long long ans = 0;
  while (low <= high) {
    long long mid = (low + high) / 2;
    if (!fun(a, b, mid, k)) {
      high = mid - 1;
    } else {
      low = mid + 1;
      ans = mid;
    }
  }
  cout << ans << endl;
}
