#include<iostream>        //比赛场数乘3减去分数之和
#include<string>
using namespace std;
int main()
{
int t,n,a,s;
string str;
while(cin>>t>>n,t)
{
s
=0;
while(t--)
{
cin
>>str>>a;
s
+=a;
}
cout
<<3*n-s<<endl;
}
return 0;
}