import java.util.Scanner;

public class Main {
    static final int N = 200005;
    static long n, m;
    static int[] a = new int[N];
    static int[] b = new int[N];
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        n = sc.nextLong();
        m = sc.nextLong();
        for (int i = 1; i <= n; ++i) a[i] = sc.nextInt();
        for (int i = 1; i <= n; ++i) b[i] = sc.nextInt();
        //准备开始进行二分查找
        int l = 0, r = N * 2;
        while (l < r) {
            int mid = (l + r + 1) >> 1;
            if (check(mid)) l = mid;
            else r = mid - 1;
        }
        System.out.println(r);
    }
   public static boolean check(int x) {
        long v = m;//现在拥有的卡牌数
        for (int i = 1; i <= n; ++i) {
            if (a[i] >= x) continue;
            if (a[i] + b[i] < x) return false;
            if (a[i] + b[i] >= x && v >= x - a[i])
                v -= (x - a[i]);
            else return false;
        }
        return true;
    }
}