def main():
    n, m = map(int, input().split())
    
    INF = float('inf')
    dp = [[INF for i in range(n+1)] for j in range(m+1)]
    
    for i, c in enumerate(list(map(int, input().split()))):
        i += 1
        for j in range(1, n+1):
            if c == j:
                dp[i][j] = 1
            else:
                dp[i][j] = min(dp[i][j], dp[i-1][j])
                if j - c >= 0: dp[i][j] = min(dp[i][j], dp[i][j-c]+1)
    print(dp[-1][-1])

if __name__ == '__main__':
    main() def main():
    n, m = map(int, input().split())
    
    INF = float('inf')
    dp = [[INF for i in range(n+1)] for j in range(m+1)]
    
    for i, c in enumerate(list(map(int, input().split()))):
        i += 1
        for j in range(1, n+1):
            if c == j:
                dp[i][j] = 1
            else:
                dp[i][j] = min(dp[i][j], dp[i-1][j])
                if j - c >= 0: dp[i][j] = min(dp[i][j], dp[i][j-c]+1)
    print(dp[-1][-1]) main n, m = map(int, input().split()) n map(int, input().split()) map int input().split() ().split () input split m INF = float('inf') INF float('inf') float 'inf' [INF for i in range(n+1)] for j in range(m+1) for j in range(m+1) j range(m+1) range m+1 m 1 for j in range(m+1) [INF for i in range(n+1)] dp = [[INF for i in range(n+1)] for j in range(m+1)] dp [[INF for i in range(n+1)] for j in range(m+1)] for i, c in enumerate(list(map(int, input().split()))):
        i += 1
        for j in range(1, n+1):
            if c == j:
                dp[i][j] = 1
            else:
                dp[i][j] = min(dp[i][j], dp[i-1][j])
                if j - c >= 0: dp[i][j] = min(dp[i][j], dp[i][j-c]+1)
     i c enumerate(list(map(int, input().split()))) enumerate list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split i += 1 i 1 for j in range(1, n+1):
            if c == j:
                dp[i][j] = 1
            else:
                dp[i][j] = min(dp[i][j], dp[i-1][j])
                if j - c >= 0: dp[i][j] = min(dp[i][j], dp[i][j-c]+1)
     j range(1, n+1) range 1 n+1 n 1 if c == j:
                dp[i][j] = 1
            else:
                dp[i][j] = min(dp[i][j], dp[i-1][j])
                if j - c >= 0: dp[i][j] = min(dp[i][j], dp[i][j-c]+1)
     c == j c j dp[i][j] = 1 dp[i][j] [i] dp i j 1 dp[i][j] = min(dp[i][j], dp[i-1][j]) dp[i][j] [i] dp i j min(dp[i][j], dp[i-1][j]) min dp[i][j] [i] dp i j dp[i-1][j] [i-1] dp i-1 i 1 j if j - c >= 0: dp[i][j] = min(dp[i][j], dp[i][j-c]+1)
     j - c >= 0 j - c j c 0 print(dp[-1][-1]) print dp[-1][-1] [-1] dp -1 -1 if __name__ == '__main__':
    main() __name__ == '__main__' __name__ '__main__' main() main def main():
    n, m = map(int, input().split())
    
    INF = float('inf')
    dp = [[INF for i in range(n+1)] for j in range(m+1)]
    
    for i, c in enumerate(list(map(int, input().split()))):
        i += 1
        for j in range(1, n+1):
            if c == j:
                dp[i][j] = 1
            else:
                dp[i][j] = min(dp[i][j], dp[i-1][j])
                if j - c >= 0: dp[i][j] = min(dp[i][j], dp[i][j-c]+1)
    print(dp[-1][-1]) def main():
    n, m = map(int, input().split())
    
    INF = float('inf')
    dp = [[INF for i in range(n+1)] for j in range(m+1)]
    
    for i, c in enumerate(list(map(int, input().split()))):
        i += 1
        for j in range(1, n+1):
            if c == j:
                dp[i][j] = 1
            else:
                dp[i][j] = min(dp[i][j], dp[i-1][j])
                if j - c >= 0: dp[i][j] = min(dp[i][j], dp[i][j-c]+1)
    print(dp[-1][-1]) main
def main():
    n, m = map(int, input().split())
    
    INF = float('inf')
    dp = [[INF for i in range(n+1)] for j in range(m+1)]
    
    for i, c in enumerate(list(map(int, input().split()))):
        i += 1
        for j in range(1, n+1):
            if c == j:
                dp[i][j] = 1
            else:
                dp[i][j] = min(dp[i][j], dp[i-1][j])
                if j - c >= 0: dp[i][j] = min(dp[i][j], dp[i][j-c]+1)
    print(dp[-1][-1])

if __name__ == '__main__':
    main()
