//
// main.cpp
// 1136 - Help R2-D2!
//
// Created by Repon Macbook on 7/5/15.
// Copyright (c) 2015 Repon Macbook. All rights reserved.
//
#include <bits/stdc++.h>
using namespace std;
/*------- Constants---- */
#define LMT 1000006
#define ll long long
#define ull unsigned long long
#define mod 1000000007
#define MEMSET_INF 63
#define MEM_VAL 1061109567
#define FOR(i,n) for( int i=0 ; i < n ; i++ )
#define mp(i,j) make_pair(i,j)
#define lop(i,a,b) for( int i = (a) ; i < (b) ; i++)
#define pb(a) push_back((a))
#define gc getchar_unlocked
#define PI acos(-1.0)
#define inf 1<<30
#define lc ((n)<<1)
#define rc ((n)<<1 |1)
#define debug(x) cout <<#x <<" -> " << x << endl;
#define EPS 1e-9
/*---- short Cuts ------- */
#define ms(ara_name,value) memset(ara_name,value,sizeof(ara_name))
typedef pair<int, int> ii;
typedef vector<int > vi ;
/*------ template functions ------ */
inline void sc(int &x)
{
register int c = gc();
x = 0;
int neg = 0;
for(;((c<48 | c>57) && c != '-');c = gc());
if(c=='-') {neg=1;c=gc();}
for(;c>47 && c<58;c = gc()) {x = (x<<1) + (x<<3) + c - 48;}
if(neg) x=-x;
}
template <class T> inline T bigmod(T p,T e,T M){
ll ret = 1;
for(; e > 0; e >>= 1){
if(e & 1) ret = (ret * p) % M;
p = (p * p) % M;
} return (T)ret;
}
template <class T> inline T gcd(T a,T b){if(b==0)return a;return gcd(b,a%b);}
template <class T> inline T modinverse(T a,T M){return bigmod(a,M-2,M);}
/*************************** END OF TEMPLATE ****************************/
int iAr[LMT];
int block;
int DP[5 * LMT];
char s[100];
void upd( int n , int b , int e ,int val ){
if( b == e ) {
iAr[b] -= val;
DP[n] -= val;
return;
}
int mid = (b+e)/2;
if(DP[lc] >= val ) {
upd(lc, b, mid, val);
}
else upd(rc, mid+1, e, val);
DP[n] = max(DP[lc] , DP[rc]);
}
int main()
{
int cap , boxes , tc = 0 ;
while(scanf("%d" ,& cap) == 1) {
scanf("%d" , &boxes );
for(int i = 0; i < boxes ; i ++ ) iAr[i] = cap;
block = sqrt(LMT ) + 1;
for(int i = 0; i < 3 * boxes + 5 ; i ++ ) DP[i] = cap;
for( int i = 0 ; i < boxes ; i ++ ) {
scanf("%s" , s);
if(s[0] == 'b' ) {
int lo , u ;
scanf("%d %d",&lo,&u );
for( int j = 0 ; i < boxes && j < lo ; i ++ , j ++ ) {
upd(1, 0, boxes - 1, u);
}
i --;
}
else {
int sum = 0;
for(int i = 0; s[i] ; i ++ ) {
sum = 10 * sum + s[i] -'0';
}
upd(1, 0, boxes - 1, sum);
}
}
ll ans = 0 ,cnt = 0 ;
for( int i = 0; i < boxes ; i ++ ) {
if(iAr[i] == cap ) break;
else {
cnt++ ;
ans += iAr[i];
}
}
if( tc) printf("\n");
printf("%lld %lld\n" , cnt , ans);
tc = 1;
}
return 0;
}
Ly8KLy8gIG1haW4uY3BwCi8vICAxMTM2IC0gSGVscCBSMi1EMiEKLy8KLy8gIENyZWF0ZWQgYnkgUmVwb24gTWFjYm9vayBvbiA3LzUvMTUuCi8vICBDb3B5cmlnaHQgKGMpIDIwMTUgUmVwb24gTWFjYm9vay4gQWxsIHJpZ2h0cyByZXNlcnZlZC4KLy8KCiNpbmNsdWRlIDxiaXRzL3N0ZGMrKy5oPgp1c2luZyBuYW1lc3BhY2Ugc3RkOwoKLyotLS0tLS0tIENvbnN0YW50cy0tLS0gKi8KI2RlZmluZSBMTVQgICAgICAgICAgICAgICAgICAgICAxMDAwMDA2CiNkZWZpbmUgbGwgICAgICAgICAgICAgICAgICAgICAgbG9uZyBsb25nCiNkZWZpbmUgdWxsICAgICAgICAgICAgICAgICAgICAgdW5zaWduZWQgbG9uZyBsb25nCiNkZWZpbmUgbW9kICAgICAgICAgICAgICAgICAgICAgMTAwMDAwMDAwNwojZGVmaW5lIE1FTVNFVF9JTkYgICAgICAgICAgICAgIDYzCiNkZWZpbmUgTUVNX1ZBTCAgICAgICAgICAgICAgICAgMTA2MTEwOTU2NwojZGVmaW5lIEZPUihpLG4pICAgICAg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KfQppbnQgbWFpbigpCnsKICAgICAgaW50IGNhcCAsIGJveGVzICwgdGMgPSAwIDsKCXdoaWxlKHNjYW5mKCIlZCIgLCYgY2FwKSA9PSAxKSB7CiAgICAgICAgICAgIAogICAgICAgICAgICBzY2FuZigiJWQiICwgJmJveGVzICk7CiAgICAgICAgICAgIGZvcihpbnQgaSA9IDA7IGkgPCBib3hlcyA7IGkgKysgKSBpQXJbaV0gPSBjYXA7CiAgICAgICAgICAgIGJsb2NrID0gc3FydChMTVQgKSArIDE7CiAgICAgICAgICAgIAogICAgICAgICAgICBmb3IoaW50IGkgPSAwOyBpIDwgMyAqIGJveGVzICsgNSA7IGkgKysgKSBEUFtpXSA9IGNhcDsKICAgICAgICAgICAgCiAgICAgICAgICAgIGZvciggaW50IGkgPSAwIDsgaSA8IGJveGVzIDsgaSArKyApIHsKICAgICAgICAgICAgICAgICAgc2NhbmYoIiVzIiAsIHMpOwogICAgICAgICAgICAgICAgICBpZihzWzBdID09ICdiJyApIHsKICAgICAgICAgICAgICAgICAgICAgICAgaW50IGxvICwgdSA7CiAgICAgICAgICAgICAgICAgICAgICAgIHNjYW5mKCIlZCAlZCIsJmxvLCZ1ICk7CiAgICAgICAgICAgICAgICAgICAgICAgCiAgICAgICAgICAgICAgICAgICAgICAgIGZvciggaW50IGogPSAwIDsgaSA8IGJveGVzICYmIGogPCBsbyA7IGkgKysgLCBqICsrICkgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgICB1cGQoMSwgMCwgYm94ZXMgLSAxLCB1KTsKICAgICAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgICAgICBpIC0tOwogICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgIGVsc2UgewogICAgICAgICAgICAgICAgICAgICAgICBpbnQgc3VtID0gMDsKICAgICAgICAgICAgICAgICAgICAgICAgZm9yKGludCBpID0gMDsgc1tpXSA7IGkgKysgKSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHN1bSA9IDEwICAqIHN1bSArIHNbaV0gLScwJzsKICAgICAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgICAgICB1cGQoMSwgMCwgYm94ZXMgLSAxLCBzdW0pOwogICAgICAgICAgICAgICAgICAgICAgICAKICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICB9CiAgICAgICAgICAgIGxsIGFucyA9IDAgLGNudCA9IDAgOwogICAgICAgICAgICBmb3IoIGludCBpID0gMDsgaSA8IGJveGVzIDsgaSArKyApIHsKICAgICAgICAgICAgICAgICAgaWYoaUFyW2ldID09IGNhcCApIGJyZWFrOwogICAgICAgICAgICAgICAgICBlbHNlIHsKICAgICAgICAgICAgICAgICAgICAgICAgY250KysgOwogICAgICAgICAgICAgICAgICAgICAgICBhbnMgKz0gaUFyW2ldOwogICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgIH0KICAgICAgICAgICAgaWYoIHRjKSBwcmludGYoIlxuIik7CiAgICAgICAgICAgIHByaW50ZigiJWxsZCAlbGxkXG4iICwgY250ICwgYW5zKTsKICAgICAgICAgICAgdGMgPSAxOwogICAgICB9CgkKCXJldHVybiAwOwp9Cg==