import java.util.Scanner; class Main{ public static void main(String[] args){ Scanner sc = new Scanner(System.in); int N = sc.nextInt(); int I = sc.nextInt(); int[][] sa = new int[N+1][2]; for(int i=1;i<=N;i++){ sa[i][0] = sc.nextInt(); sa[i][1] = sc.nextInt(); } int[][] dp = new int[N+1][I+1]; for(int i=1;i<=N;i++){ for(int j=0;j<=I;j++){ dp[i][j] = Math.max(dp[i][j],dp[i-1][j]); if(j+sa[i][0]<=I) dp[i][j+sa[i][0]] = dp[i-1][j]+sa[i][1]; } } System.out.println(dp[N][I]); } }