# coding: utf-8 import numpy as np L = int(input()) N = int(input()) length = [int(i) for i in input().split()] MAX_N,MAX_L = 10000,10000 memo = -1*np.ones((MAX_N+1,MAX_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 print(memo) return res print(int(search(0,L)))