from functools import lru_cache import sys sys.setrecursionlimit(100000) l = int(input()) n = int(input()) width = list(map(int, input().split())) @lru_cache(maxsize=None) def dp(i, w): if i == 0: return 1 if w >= width[0] else 0 else: if w >= width[i]: return max(1 + dp(i-1, w-width[i]), dp(i-1, w)) else: return dp(i-1, w) print(dp(n-1, l))