#include <iostream>
#include <cstdio>
#include <algorithm>

#define MAX_N 1000
#define MAX_W 10000

int dp[MAX_W][MAX_N], W, N, value[MAX_N], w[MAX_N];

int main(){
	int count = 0;

	while(true){
		++count;
		
		if(w == 0)
			break;

		scanf("%d%d", &W, &N);

		for(int i = 0; i < N; ++i){
			for(int j = 0; j <= W; ++j)
				dp[j][i] = 0;
		}//initialize

		for(int i = 0; i < N; ++i)
			scanf("%d,%d", &value[i], &w[i]);
		//input

		for(int i = N - 1; i >= 0; ++i){
			for(int j = 0; j < W; ++j){
				if(j < w[i])
					dp[i][j] = dp[i + 1][j];
				else
					std::max(dp[i + 1][j], dp[i + 1][j - w[i]] - value[i]);
			}
		}
		printf("count %d:%d?\n", count, dp[0][W]);
	}
	return 0;
}