'''
简单01背包问题求解
'''
N, m = map(int, input().split())
arr = []
for i in range(m):
v, p = map(int, input().split())
arr.append((v, v*p))
# dp(i,j) 表示前i种物品进行选择,在总价格不超过j的约束下,所有选法的总价值的最大值
dp = [0] * (N+1)
for i in range(m):
for j in range(N, -1, -1):
if i == 0:
dp[j] = arr[i][1] if j >= arr[i][0] else 0
else:
if j >= arr[i][0]:
dp[j] = max(dp[j], dp[j-arr[i][0]] + arr[i][1])
print(dp[N])