// Arup Guha
// 11/12/2026
// Illustration of 0-1 Knapsack Algorithm for COP 3503
// Book Shop on CSES
// https://cses.fi/problemset/task/1158/

import java.util.*;

public class bookshop {

	public static void main(String[] args) {
	
		Scanner stdin = new Scanner(System.in);
		int nBooks = stdin.nextInt();
		int maxWeight = stdin.nextInt();
		
		// Stores best value (most pages) for price i.
		int[] dp = new int[maxWeight+1];
		
		// Prices are my weights.
		int[] w = new int[nBooks];
		for (int i=0; i<nBooks; i++)
			w[i] = stdin.nextInt();
			
		// Pages are my value to maximize.
		int[] v = new int[nBooks];
		for (int i=0; i<nBooks; i++)
			v[i] = stdin.nextInt();
			
		// Consider each object one by one.
		for (int i=0; i<nBooks; i++) {
		
			// j is the weight I am filling, so j - w[i] is the weight left
			// if I were to take object i.
			for (int j=maxWeight; j>=w[i]; j--)
				dp[j] = Math.max(dp[j], dp[j-w[i]] + v[i]);
		}
		
		// Find best value for any weight.
		int res = 0;
		for (int i=0; i<=maxWeight; i++)
			res = Math.max(res, dp[i]);
		System.out.println(res);
	}
}