#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
long long int n, k;
long long int a[N];
long long int b[N];
bool check(long long int x) {
  long long needed = 0;
  for (int i = 0; i < n; ++i) {
    if (b[i] / a[i] >= x) continue;
    if (b[i] / a[i] == x - 1) {
      needed += a[i] - (b[i] % a[i]);
      continue;
    }
    needed += a[i] - (b[i] % a[i]);
    needed += (x - (1 + (b[i] / a[i]))) * a[i];
    if (needed > k) return false;
  }
  if (needed <= k) return true;
  return false;
}
int main() {
  cin >> n >> k;
  for (int i = 0; i < n; ++i) cin >> a[i];
  for (int i = 0; i < n; ++i) cin >> b[i];
  long long int s = 0, e = 1e10, mid;
  for (int i = 0; i < 100; ++i) {
    if (e - s < 2) {
      if (check(e)) return cout << e, 0;
      return cout << s, 0;
    }
    mid = s + e;
    mid /= 2;
    if (check(mid)) {
      s = mid;
      continue;
    }
    e = mid;
  }
  cout << s;
}
