#include<stdio.h>
#include<stdlib.h>
#include<string.h>

int n, max_weight,*arr;

int max(int x, int y)
{
    return x>y ? x : y;
}

int knapsack()
{
    int i,j,mem[max_weight+1];

    memset(mem,0,sizeof(mem));

    for(i=0; i<=max_weight; i++)
    {
        for(j=0; j<n; j++)
        {
            if(i >= arr[n+j]) mem[i] = max(mem[i],mem[i-arr[n+j]]+arr[j]);
        }
    }
    return mem[max_weight];
}

int main()
{
    //freopen("input.txt","r",stdin);
    scanf("%d %d",&n,&max_weight);

    arr = (int*)malloc(sizeof(int)*n*2);

    for(int i=0; i<n; i++)
    {
        scanf("%d %d",&arr[i],&arr[i+n]);
    }
    
    printf("%d\n",knapsack());

    free(arr);
    return 0;
}
