#include <stdio.h>
#define MAX_N 101
#define MAX_W 10001
 
int x[MAX_N][MAX_W];

int main() {
    int N, W, v, w;
    scanf("%d%d", &N, &W);
    for(int i=1; i<=N; i++) {
        scanf("%d%d", &v, &w);
        for(int j=1; j<=W; j++) {
            if(j-w < 0) x[i][j] = x[i-1][j];
            else x[i][j] = (x[i-1][j-w] + v > x[i-1][j]) ? x[i-1][j-w] + v : x[i-1][j];
        }
    }
    printf("%d\n", x[N][W]);
}

