P1048 [NOIP2005 普及组] 采药 - 洛谷 | 计算机科学教育新生态 (luogu.com.cn)
T, M = map(int,input().split())
dp = [[0]*(T+1) for _ in range(M+1)]
for i in range(1,M+1):
t, v = map(int,input().split())
for j in range(1,T+1):
if j<t:
dp[i][j] = dp[i-1][j]
else:
dp[i][j] = max(dp[i-1][j],dp[i-1][j-t]+v)
print(dp[M][T])