#include #define rep(i,n)for(int i=0;iP; const int MOD=1000000007; const int INF=0x3f3f3f3f; const ll INFL=0x3f3f3f3f3f3f3f3f; string s[100]; int c[100]; ll dp[320000]; int main(){ int n,K;cin>>n>>K; rep(i,n){ cin>>s[i]>>c[i]; } memset(dp,0x3f,sizeof(dp)); dp[0]=0; rep(i,3*K){ if(dp[i]==INFL)continue; rep(j,n){ int cur=i; rep(k,s[j].size()){ char want=(cur