//3117  比赛每平一局总得分就少一分 
#include<stdio.h>
main()
{
	char c;
	int n,T,t,M,sum;
	while(scanf("%d%d",&T,&M),T)
	{
		sum=0;
		t=T;
		for(;t--;)
		{
			scanf("%*s%d",&n);
			sum+=n;
		}
		printf("%ld\n",3*M-sum);	
	}	 
}