c = int(input()) n = int(input()) a = [0] + list(map(int,input().split())) dp = [[10 ** 10] * (n + 1) for i in range(c + 1)] for i in range(n + 1): dp[0][i] = 0 for i in range(1, n + 1): for j in range(c + 1): if j + a[i] <= c: dp[j + a[i]][i] = min(dp[j + a[i]][i], dp[j + a[i]][i-1], dp[j][i] + 1, dp[j][i - 1] + 1) for j in range(c + 1): dp[j][i] = min(dp[j][i], dp[j][i-1]) if dp[c][n] >= 10 ** 10: dp[c][n] = -1 print(dp[c][n])