#include <bits/stdc++.h>
using namespace std;

const int N = 1010;
int n,V,v[N],w[N],dp1[N],dp2[N];

int main(){
    cin>>n>>V;
    for(int i = 1;i<=n;i++) cin>>v[i]>>w[i];

    for(int i = 1;i<=n;i++){
        for(int j = v[i];j<=V;j++){
            dp1[j] = max(dp1[j],dp1[j-v[i]]+w[i]);
        }
    }

    for(int i = 1;i<=n;i++){
        for(int j = v[i];j<=V;j++){
            if(j-v[i]&&!dp2[j-v[i]]) continue;
            dp2[j] = max(dp2[j],dp2[j-v[i]]+w[i]);
        }
    }
    cout<<dp1[V]<<"\n"<<dp2[V];

    return 0;
}