l,n = [int(input()) for _ in range(2)] w = list(map(int, input().split())) cntDic = {} sw = [] for i in range(l): cntDic[str(i+1)] = 0 for we in w: cntDic[str(we)] += 1 for i in range(l): for _ in range(cntDic[str(i+1)]): sw.append(i+1) cnt = 0 for i, swe in enumerate(sw): cnt += swe if cnt > l: print(i) break print(cnt)