h, n = map(int, input().split())
ab = [list(map(int, input().split())) for i in range(n)]
dp = [float('inf')] * (h + 1)
dp[0] = 0
for i in range(h):
    for j in range(n):
        if dp[i] == float('inf'):
            continue
        next = i + ab[j][0] if i + ab[j][0] <= h else h
        dp[next] = min(dp[next], dp[i] + ab[j][1])
print(dp[-1])

dae7f84a84d3fdf3b1a4ac6cef5c67fdbc4f5ce8
<mask token>

<mask token>
for i in range(h):
    for j in range(n):
        if dp[i] == float('inf'):
            continue
        next = i + ab[j][0] if i + ab[j][0] <= h else h
        dp[next] = min(dp[next], dp[i] + ab[j][1])
print(dp[-1])

h, n = map(int, input().split())
ab = [list(map(int, input().split())) for i in range(n)]
dp = [float('inf')] * (h + 1)
dp[0] = 0
for i in range(h):
    for j in range(n):
        if dp[i] == float('inf'):
            continue
        next = i + ab[j][0] if i + ab[j][0] <= h else h
        dp[next] = min(dp[next], dp[i] + ab[j][1])
print(dp[-1])
