#include<iostream>
using namespace std;
int main()
{
int V, N, Case;
int i, j;
int *p, *volume , *value;
cin >> N;
cin >> V;
volume = new int[N + 1];
value = new int[N + 1];
value[0] = 0;
for (i = 1; i <= N; i++)
cin >> value[i];
volume[0] = 0;
for (i = 1; i <= N; i++)
cin >> volume[i];
p = new int[V + 1];
for (i = 0; i <= V; i++)
p[i] = 0;
for (i = 1; i <= N; i++)
{
for (j = V; j >= volume[i]; j--)
{
if (p[j - volume[i]] + value[i] > p[j])
p[j] = p[j - volume[i]]+ value[i];
else
p[j] = p[j];
}
}
cout << p[V] << endl;
delete []p; p = NULL;
delete []volume; volume = NULL;
delete []value; value = NULL;
return 0;
}