#include <bits/stdc++.h>
using namespace std;
vector<long long int> a, b;
long long int k, n;
bool check(long long int num) {
  long long int extra = 0;
  for (int i = 0; i < n; i++) {
    if (b[i] >= a[i] * num) continue;
    extra += a[i] * num - b[i];
  }
  return (extra <= k);
}
int main() {
  long long int x;
  cin >> n >> k;
  for (int i = 0; i < n; i++) {
    cin >> x;
    a.push_back(x);
  }
  for (int i = 0; i < n; i++) {
    cin >> x;
    b.push_back(x);
  }
  long long int b = 0, e = 1e13;
  long long int res = 0;
  while (b <= e) {
    int mid = (b + e) / 2;
    if (check(mid)) {
      res = mid;
      b = mid + 1;
    } else {
      e = mid - 1;
    }
  }
  cout << res << endl;
  return 0;
}
