import sys input = sys.stdin.readline N,K=map(int,input().split()) S=[input().split() for i in range(N)] DP=[1<<63]*(3*K+2+100) DP[0]=0 T=["J"]*K+["O"]*K+["I"]*K J=[] O=[] I=[] for s,M in S: J.append((s.count("J"),int(M))) O.append((s.count("O"),int(M))) I.append((s.count("I"),int(M))) from fractions import Fraction MAXJ=max(J,key=lambda x:Fraction(x[0],x[1])) MAXO=max(O,key=lambda x:Fraction(x[0],x[1])) MAXI=max(I,key=lambda x:Fraction(x[0],x[1])) for i in range(3*K): #NEXT=T[i:i+80] if i