def solution(A, N) -> int:
i = 1
while True:
if i not in A:
return i
i += 1
assert solution([1, 3, 6, 4, 1, 2], 6) == 5
assert solution([1, 2, 3], 3) == 4
assert solution([-1, -3], 2) == 1
ZGVmIHNvbHV0aW9uKEEsIE4pIC0+IGludDoKICAgIGkgPSAxCiAgICB3aGlsZSBUcnVlOgogICAgICAgIGlmIGkgbm90IGluIEE6CiAgICAgICAgICAgIHJldHVybiBpCiAgICAgICAgaSArPSAxCgphc3NlcnQgc29sdXRpb24oWzEsIDMsIDYsIDQsIDEsIDJdLCA2KSA9PSA1CmFzc2VydCBzb2x1dGlvbihbMSwgMiwgM10sIDMpID09IDQKYXNzZXJ0IHNvbHV0aW9uKFstMSwgLTNdLCAyKSA9PSAx