#include <bits/stdc++.h>
const long double EPS = 1e-10;
const long long int MOD = 1000000007ll;
const long long int mod1 = 1000000009ll;
const long long int mod2 = 1100000009ll;
int INF = 2147483645;
long long int INFINF = 9223372036854775807;
int debug = 0;
using namespace std;
void print(int a[], int s, int e) {
  for (int i = s; i <= e; i++) cout << a[i] << " ";
  cout << "\n";
}
void print(vector<int> &v, int s, int e) {
  for (int i = s; i <= e; i++) cout << v[i] << " ";
  cout << "\n";
}
void print(vector<int> &v) {
  for (int x : v) cout << x << " ";
  cout << "\n";
}
long long int bit_count(long long int _x) {
  long long int _ret = 0;
  while (_x) {
    if (_x % 2 == 1) _ret++;
    _x /= 2;
  }
  return _ret;
}
long long int bit(long long int _mask, long long int _i) {
  return (_mask & (1 << _i)) == 0 ? 0 : 1;
}
long long int powermod(long long int _a, long long int _b, long long int _m) {
  long long int _r = 1;
  while (_b) {
    if (_b % 2 == 1) _r = (_r * _a) % _m;
    _b /= 2;
    _a = (_a * _a) % _m;
  }
  return _r;
}
long long int add(long long int a, long long int b, long long int m = MOD) {
  long long int x = a + b;
  while (x >= m) x -= m;
  return x;
}
long long int sub(long long int a, long long int b, long long int m = MOD) {
  long long int x = a - b;
  while (x < 0) x += m;
  return x;
}
long long int mul(long long int a, long long int b, long long int m = MOD) {
  long long int x = a * b;
  x %= m;
  return x;
}
long long int n, k;
long long int a[100010], b[100010];
bool check(long long int x) {
  long long int req = k;
  for (int i = 1; i <= n; i++) {
    if (a[i] * x > b[i]) {
      req -= a[i] * x - b[i];
      if (req < 0) return false;
    }
  }
  return req >= 0;
}
int main() {
  srand(time(NULL));
  scanf("%lld", &n);
  ;
  scanf("%lld", &k);
  ;
  for (int i = 1; i <= n; i++) scanf("%lld", &a[i]);
  ;
  for (int i = 1; i <= n; i++) scanf("%lld", &b[i]);
  ;
  long long int low = 0, high = ((long long int)2e9) + 10, mid, idx = 0;
  while (low <= high) {
    mid = (low + high) >> 1;
    if (check(mid)) {
      idx = mid;
      low = mid + 1;
    } else
      high = mid - 1;
  }
  cout << idx;
  return 0;
}
