#include <iostream>
#include <algorithm>
using namespace std;
int N, V;
const int MAX_N = 100 + 5, MAX_V = 1000 + 5;
int w[MAX_N], c[MAX_N], dp[MAX_V];
int main() {
cin >> N >> V;
for (int n = 0; n < N; n++) {
cin >> w[n + 1];
}
for (int n = 0; n < N; n++) {
cin >> c[n + 1];
}
// boundary
for (int v = 0; v < V; v++) {
dp[v] = 0;
}
for (int i = 1; i <= N; i++) {
for (int v = w[i]; v <= V; v++) {
dp[v] = max(dp[v], dp[v - w[i]] + c[i]);
}
}
cout << *max_element(dp + 1, dp + V + 1) << endl;
return 0;
}
/*
Sample Input:
5 8
3 5 1 2 2
4 5 2 1 3
Sample Output:
16
*/