#include <algorithm>
#include <array>
#include <cstdio>
#include <utility>
#include <vector>
using namespace std;

int main() {
	int N, M;
	scanf("%d %d", &N, &M);
	vector<array<int, 2> > V(N);
	for (int j = 0; j < 2; j++) {
		for (int i = 0; i < N; i++) {
			scanf("%d", &V[i][j]);
		}
	}
	sort(V.begin(), V.end());
	long long ans = M;
	for (auto &x : V) {
		if (x[0] >= x[1]) continue;
		if (x[0] > ans) continue;
		ans += x[1] - x[0];
	}
	printf("%lld\n", ans);
	return 0;
}
