#include <bits/stdc++.h>
using namespace std;
long long a[100005], b[100005];
int main() {
  long long i, j, k;
  long long n, m;
  cin >> n >> k;
  for (i = 0; i < n; i++) {
    cin >> a[i];
  }
  for (i = 0; i < n; i++) {
    cin >> b[i];
  }
  long long high, low, mid, ans;
  high = 2000000005, low = 0, ans = 0;
  long long cnt;
  while (low <= high) {
    mid = (low + high) / 2;
    cnt = 0;
    for (i = 0; i < n; i++) {
      cnt += max((long long)0, mid * a[i] - b[i]);
      if (cnt > k) {
        break;
      }
    }
    if (cnt == k) {
      ans = mid;
      break;
    }
    if (cnt > k) {
      high = mid - 1;
    } else {
      low = mid + 1;
      ans = max(ans, mid);
    }
  }
  cout << ans;
  return 0;
}
