cho.sh
Notes
Loading...

Choosing Three Numbers

Time limit

2s

Memory limit

128 MB

Problem

You are given a positive integer N and a set S containing M positive integers.

Choose positive integers x, y, and z, each of which is not in S. Find the minimum possible value of |N - xyz|.

Input

The first line contains N (1 <= N <= 1,000) and M (0 <= M <= 50), the size of S.

The second line contains the numbers in S, separated by spaces. Each number is a positive integer at most 1,000, and no number appears more than once.

If M is 0, the second line is empty.

Output

Print the minimum possible value of |N - xyz| on the first line.