#include <cstdio>
#include <vector>
using namespace std;

int main() {
	int N, M;
	scanf("%d %d", &N, &M);
	vector<int> A(N), B(N);
	for (int &i : A) {
		scanf("%d", &i);
	}
	for (int &i : B) {
		scanf("%d", &i);
	}
	// while there is something for me to do:
	while (true) {
		// try to find any profitable task that I can do
		int todo = -1;
		for (int i = 0; i < A.size(); i++) {
			if (A[i] < B[i] && A[i] <= M) todo = i;
		}
		if (todo == -1) {
			break; // cannot do anything
		}
		M += B[todo] - A[todo];
		swap(A[todo], A.back());
		A.pop_back();
		swap(B[todo], B.back());
		B.pop_back();
	}
	printf("%d\n", M);
	return 0;
}
