#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef long double ld;
const int inf=1e9+7;
const ll longinf=1LL<<60;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define F first
#define S second
constexpr char ln =  '\n';

const int mx=100010;
const ll mod=1e9+7;


int main(){
  int n,t;
  cin >> n >> t;
  vector<P> a(n);
  rep(i,n){
    cin >> a[i].F >> a[i].S;
  }
  sort(a.begin(),a.end());

  vector<vector<ll>> dp(3010, vector<ll>(6010,0));
  rep(i,n)rep(j,6005){
    dp[i+1][j] = dp[i][j];
    if(j-a[i].F>=0 && j-a[i].F<t){
      dp[i+1][j] = max(dp[i+1][j], dp[i][j-a[i].F] + a[i].S);
    }
  }
  ll ans = 0;
  rep(i,6005){
    ans = max(ans, dp[n][i]);
  }
  cout << ans << ln;
  return 0;
}
#include<bits/stdc++.h>
using namespace std;
int main(){
    ios::sync_with_stdio(false);
    cin.tie();
    int n, m;
    cin>>n>>m;
    if(n == 0 || m == 0){
        cout<<"0 0";
        return 0;
    }    
    bool accepted[n];
    unordered_map<int, int> ma;
    for(int i = 0; i < n; i++){
        accepted[i] = false;
    }
    for(int i = 0; i < m; i++){
        int p; string s;
        cin>>p>>s;
        p-=1;
        if(s == "AC"){
            accepted[p] = true;
        }else{
            if(!accepted[p]){
                if(ma.find(p) == ma.end()){
                    ma[p] = 1;
                }else
                {
                    ma[p]++;
                }
                
            }
        }
    }                 
    int correct = 0, penalties = 0;
    for(int i = 0; i < n; i++){
        if(accepted[i]){
            correct++;
            penalties += ma[i];
        }
    }                         
    cout<<correct<<" "<<penalties;                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      
    return 0;
}