#include <bits/stdc++.h>
using namespace std;
int main() {
  long long i, n_ingredients, magicpowder, n_cakes = 0, cost = 0;
  cin >> n_ingredients >> magicpowder;
  vector<long long> b(n_ingredients), a(n_ingredients);
  for (i = 0; i < n_ingredients; i++) cin >> a[i];
  for (i = 0; i < n_ingredients; i++) cin >> b[i];
  map<long long, long long> events;
  for (i = 0; i < n_ingredients; i++) {
    long long time = b[i] / a[i];
    events[time] += a[i] - b[i] % a[i];
    events[time + 1] += b[i] % a[i];
  }
  for (auto event : events) {
    long long nextevent = event.first;
    long long n_possiblecakes = cost != 0 ? magicpowder / cost : 1e10;
    if (n_cakes + n_possiblecakes > nextevent) {
      magicpowder -= (nextevent - n_cakes) * cost;
      n_cakes = nextevent;
      cost += event.second;
    } else {
      n_cakes += n_possiblecakes;
      magicpowder -= n_possiblecakes * cost;
      break;
    }
  }
  cout << n_cakes + magicpowder / cost << endl;
  return 0;
}
