#include <bits/stdc++.h>
using namespace std;
int n, k;
vector<int> a;
vector<int> b;
bool megcsinalhato(int sutik) {
  int cnt = 0;
  for (int i = 0; i < n; i++) {
    if (a[i] * sutik > b[i]) {
      cnt += a[i] * sutik - b[i];
    }
  }
  if (cnt > k)
    return 0;
  else
    return 1;
}
int main() {
  cin >> n >> k;
  a.resize(n);
  b.resize(n);
  for (int &x : a) cin >> x;
  for (int &x : b) cin >> x;
  int lo = 0, hi = 0;
  for (int i = 0; i < n; i++) {
    hi = max(hi, b[i] / a[i] + k);
  }
  while (lo < hi) {
    int mid = (lo + hi + 1) / 2;
    cerr << mid << "\n";
    if (megcsinalhato(mid)) {
      lo = mid;
    } else {
      hi = mid - 1;
    }
  }
  cout << lo;
  return 0;
}
