H, N  = list(map(int, input().split()))

# hitpoint H

# waza N

As = [] # damage

Bs = [] # MP comsumptions

for i in range(N):

    a,b = list(map(int, input().split()))

    As.append(a)

    Bs.append(b)



"""

dp[i][j] = i番目までの魔法を見たとき、ダメージがちょうどjになる最小値

"""

INF = 10**10

M = 21000

dp = [[INF]*M for i in range(N+1)]

dp[0][0] = 0

for i,(a,b) in enumerate(zip(As,Bs)):

    dp[i+1][:] = dp[i][:]

    for j in range(H):        

        dp[i+1][j+a] = min(dp[i][j+a], dp[i+1][j]+b)

        # print(i,j,"ab",a,b,"dp",dp[i][j],dp[i][j+1],dp[i][j]+b)

print((min(dp[N][H:])))

H, N  = list(map(int, input().split()))

# hitpoint H

# waza N

As = [] # damage

Bs = [] # MP comsumptions

for i in range(N):

    a,b = list(map(int, input().split()))

    As.append(a)

    Bs.append(b)



INF = 10**10

M = 21000

dp = [INF]*M

dp[0] = 0

for i,(a,b) in enumerate(zip(As,Bs)):

    # update

    for j in range(H):

        # 何回でも使っていい⇛dp[i+1][j]+b

        dp[j+a] = min(dp[j+a], dp[j]+b) 

print((min(dp[H:])))



H, N = list(map(int, input().split()))
# hitpoint H
# waza N
As = []  # damage
Bs = []  # MP comsumptions
for i in range(N):
    a, b = list(map(int, input().split()))
    As.append(a)
    Bs.append(b)
"""
dp[i][j] = i番目までの魔法を見たとき、ダメージがちょうどjになる最小値
"""
INF = 10**10
M = 21000
dp = [[INF] * M for i in range(N + 1)]
dp[0][0] = 0
for i, (a, b) in enumerate(zip(As, Bs)):
    dp[i + 1][:] = dp[i][:]
    for j in range(H):
        dp[i + 1][j + a] = min(dp[i][j + a], dp[i + 1][j] + b)
        # print(i,j,"ab",a,b,"dp",dp[i][j],dp[i][j+1],dp[i][j]+b)
print((min(dp[N][H:])))

H, N = list(map(int, input().split()))
# hitpoint H
# waza N
As = []  # damage
Bs = []  # MP comsumptions
for i in range(N):
    a, b = list(map(int, input().split()))
    As.append(a)
    Bs.append(b)
INF = 10**10
M = 21000
dp = [INF] * M
dp[0] = 0
for i, (a, b) in enumerate(zip(As, Bs)):
    # update
    for j in range(H):
        # 何回でも使っていい⇛dp[i+1][j]+b
        dp[j + a] = min(dp[j + a], dp[j] + b)
print((min(dp[H:])))

-""" -dp[i][j] = i番目までの魔法を見たとき、ダメージがちょうどjになる最小値 -""" -dp = [[INF] * M for i in range(N + 1)] -dp[0][0] = 0 +dp = [INF] * M +dp[0] = 0 -    dp[i + 1][:] = dp[i][:] +    # update -        dp[i + 1][j + a] = min(dp[i][j + a], dp[i + 1][j] + b) -        # print(i,j,"ab",a,b,"dp",dp[i][j],dp[i][j+1],dp[i][j]+b) -print((min(dp[N][H:]))) +        # 何回でも使っていい⇛dp[i+1][j]+b +        dp[j + a] = min(dp[j + a], dp[j] + b) +print((min(dp[H:])))