# /usr/bin/env python # -*- coding: utf-8 -*- l = int(input()) n = int(input()) w = list(map(int,input().split())) w.sort a = [] for i in range(0,n+1): a.append(w[i]) if sum(a) > l: a.pop(-1) break print(w) print(len(a))