#include using namespace std; const int maxn = 1e5+100; const int inf = 0x7fffffff; typedef long long ll; struct monster { int a,b; }a[maxn]; struct du { int k,p; }b[maxn]; int dp[1005][20]; int main(void) { int n,m; while(~scanf("%d %d",&n,&m)) { memset(dp,-1,sizeof(dp)); for(int i=0;idp[cc][j]+b[i].k) dp[k][j] = dp[cc][j]+b[i].k; } } } ll ans = 0; for(int i=0;i