import java.io.*;
import java.util.*;

public class solution {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        long M = sc.nextLong();
        int [] A = new int[N];
        for (int i = 0; i < N; i++) {
            A[i] = sc.nextInt();
        }
        int [] B = new int[N];
        for (int i = 0; i < N; i++) {
            B[i] = sc.nextInt();
        }
        Integer [] inx = new Integer[N];
        for (int i = 0; i < N; i++) {
            inx[i] = new Integer(i);
        }
        Arrays.sort(inx, new Comparator<Integer>() {
           @Override
            public int compare(Integer a, Integer b) {
                return A[a] - A[b];
            }
        });
        for (int i = 0; i < N; i++) {
            int waiter = inx[i];
            if (A[waiter] > B[waiter]) continue;
            if (M >= A[waiter]) M += B[waiter] - A[waiter];
        }
        System.out.println(M);
    }
}
