#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:102400000000,102400000000")
const long long MOD = 1000000007;
const int N = 1e5 + 15;
const int maxn = 8e3 + 15;
const int letter = 130;
const int INF = 2e9;
const double pi = acos(-1.0);
const double eps = 1e-10;
using namespace std;
inline int read() {
  int x = 0, f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  return x * f;
}
int n;
long long k;
long long a[N], b[N];
struct node {
  long long x, y, z;
  node() {}
  node(int x, int y, int z) : x(x), y(y), z(z) {}
  bool operator<(const node &p) const { return x < p.x; }
} c[N];
struct cnode {
  long long x, y, z;
  cnode() {}
  cnode(int x, int y, int z) : x(x), y(y), z(z) {}
  bool operator<(const cnode &p) const { return x > p.x; }
};
priority_queue<cnode> pq;
int main() {
  scanf("%d%I64d", &n, &k);
  for (int i = 0; i < n; i++) scanf("%I64d", a + i);
  for (int i = 0; i < n; i++) scanf("%I64d", b + i);
  for (int i = 0; i < n; i++) {
    c[i].x = b[i] / a[i];
    c[i].y = a[i] - b[i] % a[i];
    c[i].z = a[i];
  }
  sort(c, c + n);
  int cnt = 0;
  for (int i = 1; i < n; i++) {
    if (c[i].x == c[i - 1].x) {
      c[cnt].y += c[i].y;
      c[cnt].z += c[i].z;
    } else {
      cnt++;
      c[cnt].x = c[i].x;
      c[cnt].y = c[i].y;
      c[cnt].z = c[i].z;
    }
  }
  while (!pq.empty()) pq.pop();
  for (int i = 0; i <= cnt; i++) {
    pq.push(cnode(c[i].x, c[i].y, c[i].z));
  }
  while (!pq.empty()) {
    long long x = pq.top().x;
    long long y = pq.top().y;
    long long z = pq.top().z;
    pq.pop();
    if (pq.empty()) {
      if (k >= y) x++, k -= y, x = x + k / z;
      pq.push(cnode(x, y, z));
      break;
    }
    if (k < y) {
      pq.push(cnode(x, y, z));
      break;
    }
    k -= y;
    x++;
    y = z;
    if (x == pq.top().x) {
      long long zz = pq.top().z;
      long long yy = pq.top().y;
      pq.pop();
      zz += z;
      pq.push(cnode(x, yy + z, zz));
    } else {
      long long xx = pq.top().x;
      if ((xx - x) * z >= k) {
        x = x + k / z;
        pq.push(cnode(x, y, z));
        break;
      } else {
        k -= (xx - x) * z;
        long long zz = pq.top().z;
        long long yy = pq.top().y;
        pq.pop();
        zz += z;
        pq.push(cnode(xx, yy + z, zz));
      }
    }
  }
  printf("%I64d\n", pq.top().x);
  return 0;
}
