#!/usr/bin/env python
# -*- coding: utf-8 -*-

"""
input:
15 6
1 2 7 8 12 50

output:
2
"""

import sys


def solve():
    rec[0] = 0
    for i in range(c_num):
        for j in range(money - coins[i] + 1):
            rec[j + coins[i]] = min(rec[j + coins[i]], rec[j] + 1)

    return rec


if __name__ == '__main__':
    _input = sys.stdin.readlines()
    money, c_num = map(int, _input[0].split())
    coins = list(map(int, _input[1].split()))
    assert len(coins) == c_num
    rec = [float('inf')] * (money + 1)
    ans = solve()
    print(ans[-1]) """
input:
15 6
1 2 7 8 12 50

output:
2
""" import sys sys def solve():
    rec[0] = 0
    for i in range(c_num):
        for j in range(money - coins[i] + 1):
            rec[j + coins[i]] = min(rec[j + coins[i]], rec[j] + 1)

    return rec solve rec[0] = 0 rec[0] rec 0 0 for i in range(c_num):
        for j in range(money - coins[i] + 1):
            rec[j + coins[i]] = min(rec[j + coins[i]], rec[j] + 1)

     i range(c_num) range c_num for j in range(money - coins[i] + 1):
            rec[j + coins[i]] = min(rec[j + coins[i]], rec[j] + 1)

     j range(money - coins[i] + 1) range money - coins[i] + 1 money - coins[i] money coins[i] coins i 1 rec[j + coins[i]] = min(rec[j + coins[i]], rec[j] + 1) rec[j + coins[i]] rec j + coins[i] j coins[i] coins i min(rec[j + coins[i]], rec[j] + 1) min rec[j + coins[i]] rec j + coins[i] j coins[i] coins i rec[j] + 1 rec[j] rec j 1 return rec rec if __name__ == '__main__':
    _input = sys.stdin.readlines()
    money, c_num = map(int, _input[0].split())
    coins = list(map(int, _input[1].split()))
    assert len(coins) == c_num
    rec = [float('inf')] * (money + 1)
    ans = solve()
    print(ans[-1]) __name__ == '__main__' __name__ '__main__' _input = sys.stdin.readlines() _input sys.stdin.readlines() sys.stdin.readlines sys.stdin sys stdin readlines money, c_num = map(int, _input[0].split()) money map(int, _input[0].split()) map int _input[0].split() [0].split [0] _input 0 split c_num coins = list(map(int, _input[1].split())) coins list(map(int, _input[1].split())) list map(int, _input[1].split()) map int _input[1].split() [1].split [1] _input 1 split assert len(coins) == c_num len(coins) == c_num len(coins) len coins c_num rec = [float('inf')] * (money + 1) rec [float('inf')] * (money + 1) [float('inf')] float('inf') float 'inf' money + 1 money 1 ans = solve() ans solve() solve print(ans[-1]) print ans[-1] ans -1 ans = solve() solve() ans rec = [float('inf')] * (money + 1) [float('inf')] * (money + 1) rec def solve():
    rec[0] = 0
    for i in range(c_num):
        for j in range(money - coins[i] + 1):
            rec[j + coins[i]] = min(rec[j + coins[i]], rec[j] + 1)

    return rec def solve():
    rec[0] = 0
    for i in range(c_num):
        for j in range(money - coins[i] + 1):
            rec[j + coins[i]] = min(rec[j + coins[i]], rec[j] + 1)

    return rec solve _input = sys.stdin.readlines() sys.stdin.readlines() _input money, c_num = map(int, _input[0].split()) map(int, _input[0].split()) money c_num = map(int, _input[0].split()) map(int, _input[0].split()) c_num coins = list(map(int, _input[1].split())) list(map(int, _input[1].split())) coins
#!/usr/bin/env python
# -*- coding: utf-8 -*-

"""
input:
15 6
1 2 7 8 12 50

output:
2
"""

import sys


def solve():
    rec[0] = 0
    for i in range(c_num):
        for j in range(money - coins[i] + 1):
            rec[j + coins[i]] = min(rec[j + coins[i]], rec[j] + 1)

    return rec


if __name__ == '__main__':
    _input = sys.stdin.readlines()
    money, c_num = map(int, _input[0].split())
    coins = list(map(int, _input[1].split()))
    assert len(coins) == c_num
    rec = [float('inf')] * (money + 1)
    ans = solve()
    print(ans[-1])