def read_data(): C = int(input()) N = int(input()) As = list(map(int, input().split())) return C, N, As def solve(C, N, As): As.sort() lower, residue = divmod(C, As[-1]) if residue == 0: return lower lower += 1 upper = C // As[0] for total in range(lower, upper + 1): if has_solution(total, C, As, N-1): return total return -1 def has_solution(total, C, As, idx): a = As[idx] if idx == 0: n, r = divmod(C, a) return r == 0 and n == total for n in range(C//a, -1, -1): new_total = total - n new_C = C - n * a if new_C > new_total * As[idx - 1]: return False result = has_solution(new_total, new_C, As, idx - 1) if result: return True return False C, N, As = read_data() print(solve(C, N, As))