# coding: utf-8 import numpy as np L = int(input()) N = int(input()) length = [int(i) for i in input().split()] memo = -1*np.ones((N+1,L+1)) def search(i,j): if memo[i,j] != -1: return memo[i,j] else: if i == N: res = 0 elif j < length[i]: res = search(i+1,j) else: res = max(search(i+1, j), search(i+1, j - length[i]) + 1) memo[i,j] = res return res print(search(0,L))