import sys input = lambda :sys.stdin.readline()[:-1] ni = lambda :int(input()) na = lambda :list(map(int,input().split())) sys.setrecursionlimit(10**7) yes = lambda :print("yes");Yes = lambda :print("Yes");YES = lambda : print("YES") no = lambda :print("no");No = lambda :print("No");NO = lambda : print("NO") ####################################################################### c = ni() n = ni() a = na() a = sorted(set(a)) n = len(a) from collections import deque d = deque([0]) inf = 10**9 dp = [inf for i in range(c+1)] dp[0] = 0 while d: e = d.popleft() for i in a: if i+e>c: break if dp[i+e]!=inf:continue dp[i+e] = dp[e]+1 d.append(i+e) if dp[-1]==inf: print(-1) else: print(dp[-1])