# -*- coding: utf-8 -*-
import sys
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
input=lambda: sys.stdin.readline().rstrip()
YesNo=lambda b: print('Yes' if b else 'No')
YESNO=lambda b: print('YES' if b else 'NO')

def main():
    N,M=map(int,input().split())
    c=list(map(int,input().split()))
    dp=[[INF]*10**6 for _ in range(M+1)]
    dp[0][0]=0
    ans=INF
    for i in range(M):
        for money in range(N+1):
            dp[i+1][money]=min(dp[i+1][money],dp[i][money])
            if money-c[i]>=0:
                dp[i+1][money]=min(dp[i+1][money],dp[i][money-c[i]]+1,dp[i+1][money-c[i]]+1)
    print(dp[M][N])

if __name__ == '__main__':
    main()
 import sys sys sys.setrecursionlimit(10**9) sys.setrecursionlimit sys setrecursionlimit 10**9 10 9 INF=10**18 INF 10**18 10 18 MOD=10**9+7 MOD 10**9+7 10**9 10 9 7 input=lambda: sys.stdin.readline().rstrip() input lambda: sys.stdin.readline().rstrip() sys.stdin.readline().rstrip() sys.stdin.readline().rstrip sys.stdin.readline() sys.stdin.readline sys.stdin sys stdin readline rstrip YesNo=lambda b: print('Yes' if b else 'No') YesNo lambda b: print('Yes' if b else 'No') print('Yes' if b else 'No') print 'Yes' if b else 'No' b 'Yes' 'No' b YESNO=lambda b: print('YES' if b else 'NO') YESNO lambda b: print('YES' if b else 'NO') print('YES' if b else 'NO') print 'YES' if b else 'NO' b 'YES' 'NO' b def main():
    N,M=map(int,input().split())
    c=list(map(int,input().split()))
    dp=[[INF]*10**6 for _ in range(M+1)]
    dp[0][0]=0
    ans=INF
    for i in range(M):
        for money in range(N+1):
            dp[i+1][money]=min(dp[i+1][money],dp[i][money])
            if money-c[i]>=0:
                dp[i+1][money]=min(dp[i+1][money],dp[i][money-c[i]]+1,dp[i+1][money-c[i]]+1)
    print(dp[M][N]) main N,M=map(int,input().split()) N map(int,input().split()) map int input().split() ().split () input split M c=list(map(int,input().split())) c list(map(int,input().split())) list map(int,input().split()) map int input().split() ().split () input split [INF]*10**6 for _ in range(M+1) for _ in range(M+1) _ range(M+1) range M+1 M 1 for _ in range(M+1) [INF]*10**6 [INF] INF 10**6 10 6 dp=[[INF]*10**6 for _ in range(M+1)] dp [[INF]*10**6 for _ in range(M+1)] dp[0][0]=0 dp[0][0] [0] dp 0 0 0 ans=INF ans INF for i in range(M):
        for money in range(N+1):
            dp[i+1][money]=min(dp[i+1][money],dp[i][money])
            if money-c[i]>=0:
                dp[i+1][money]=min(dp[i+1][money],dp[i][money-c[i]]+1,dp[i+1][money-c[i]]+1)
     i range(M) range M for money in range(N+1):
            dp[i+1][money]=min(dp[i+1][money],dp[i][money])
            if money-c[i]>=0:
                dp[i+1][money]=min(dp[i+1][money],dp[i][money-c[i]]+1,dp[i+1][money-c[i]]+1)
     money range(N+1) range N+1 N 1 dp[i+1][money]=min(dp[i+1][money],dp[i][money]) dp[i+1][money] [i+1] dp i+1 i 1 money min(dp[i+1][money],dp[i][money]) min dp[i+1][money] [i+1] dp i+1 i 1 money dp[i][money] [i] dp i money if money-c[i]>=0:
                dp[i+1][money]=min(dp[i+1][money],dp[i][money-c[i]]+1,dp[i+1][money-c[i]]+1)
     money-c[i]>=0 money-c[i] money c[i] c i 0 dp[i+1][money]=min(dp[i+1][money],dp[i][money-c[i]]+1,dp[i+1][money-c[i]]+1) dp[i+1][money] [i+1] dp i+1 i 1 money min(dp[i+1][money],dp[i][money-c[i]]+1,dp[i+1][money-c[i]]+1) min dp[i+1][money] [i+1] dp i+1 i 1 money dp[i][money-c[i]]+1 dp[i][money-c[i]] [i] dp i money-c[i] money c[i] c i 1 dp[i+1][money-c[i]]+1 dp[i+1][money-c[i]] [i+1] dp i+1 i 1 money-c[i] money c[i] c i 1 print(dp[M][N]) print dp[M][N] [M] dp M N if __name__ == '__main__':
    main() __name__ == '__main__' __name__ '__main__' main() main YesNo=lambda b: print('Yes' if b else 'No') lambda b: print('Yes' if b else 'No') YesNo input=lambda: sys.stdin.readline().rstrip() lambda: sys.stdin.readline().rstrip() input INF=10**18 10**18 INF def main():
    N,M=map(int,input().split())
    c=list(map(int,input().split()))
    dp=[[INF]*10**6 for _ in range(M+1)]
    dp[0][0]=0
    ans=INF
    for i in range(M):
        for money in range(N+1):
            dp[i+1][money]=min(dp[i+1][money],dp[i][money])
            if money-c[i]>=0:
                dp[i+1][money]=min(dp[i+1][money],dp[i][money-c[i]]+1,dp[i+1][money-c[i]]+1)
    print(dp[M][N]) def main():
    N,M=map(int,input().split())
    c=list(map(int,input().split()))
    dp=[[INF]*10**6 for _ in range(M+1)]
    dp[0][0]=0
    ans=INF
    for i in range(M):
        for money in range(N+1):
            dp[i+1][money]=min(dp[i+1][money],dp[i][money])
            if money-c[i]>=0:
                dp[i+1][money]=min(dp[i+1][money],dp[i][money-c[i]]+1,dp[i+1][money-c[i]]+1)
    print(dp[M][N]) main YESNO=lambda b: print('YES' if b else 'NO') lambda b: print('YES' if b else 'NO') YESNO MOD=10**9+7 10**9+7 MOD
# -*- coding: utf-8 -*-
import sys
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
input=lambda: sys.stdin.readline().rstrip()
YesNo=lambda b: print('Yes' if b else 'No')
YESNO=lambda b: print('YES' if b else 'NO')

def main():
    N,M=map(int,input().split())
    c=list(map(int,input().split()))
    dp=[[INF]*10**6 for _ in range(M+1)]
    dp[0][0]=0
    ans=INF
    for i in range(M):
        for money in range(N+1):
            dp[i+1][money]=min(dp[i+1][money],dp[i][money])
            if money-c[i]>=0:
                dp[i+1][money]=min(dp[i+1][money],dp[i][money-c[i]]+1,dp[i+1][money-c[i]]+1)
    print(dp[M][N])

if __name__ == '__main__':
    main()

