#include <bits/stdc++.h>
using namespace std;
long long n, k;
long long a[100005];
long long b[100005];
int main() {
  while (cin >> n >> k) {
    int aux;
    for (int i = 0; i < n; i++) {
      scanf("%d", &aux);
      a[i] = aux;
    }
    for (int i = 0; i < n; i++) {
      scanf("%d", &aux);
      b[i] = aux;
    }
    long long lo = 0;
    long long hi = 3000000001;
    for (int caso = 0; caso < 40; caso++) {
      long long me = (lo + hi) / 2;
      long long cuenta = 0;
      bool ok = 1;
      for (int i = 0; i < n; i++) {
        if (a[i] * me <= b[i]) continue;
        cuenta += a[i] * me - b[i];
        if (cuenta > k) {
          ok = 0;
          break;
        }
      }
      if (cuenta <= k && ok) {
        lo = me;
      } else {
        hi = me;
      }
    }
    cout << lo << endl;
  }
  return 0;
}
