
solve n []
	| n >= 0 = n
	| otherwise = -1
solve n (a:as) = solve (n - a) as

main = do
	line1 <- getLine
	let n = read . head $ words line1
	line2 <- getLine
	let as = map (read) . words $ line2
	putStrLn $ show $ solve n as

