This page is still under construction.

Parts of this page are still being built. What you see may change.

Password Creation

Interview

Time limit1sMemory limit1024 MB

Summary
Given N and a set of M used passwords, choose a password from 0 to N maximizing the minimum Hamming distance to any used password.
Level

Medium6 of 10

Topics
Bit manipulation, Binary search, Greedy, Math
Solved
No attempts yet

Problem

Hyangbin works as a security officer in the computer lab at Sogang University. One day he receives an email. The email says that abnormal login attempts on the server administrator account have been detected, and the attached file contains the list of passwords used in the login attempts so far. The password for the server administrator account can be any integer from 00 to NN.

The safety distance between two passwords is defined as the number of positions where the two passwords differ in binary representation. For example, 33 in binary is 00110011 and 88 in binary is 10001000. They differ in 33 positions, so the safety distance between 33 and 88 is 33.

The safety level of a password is defined as the minimum of its safety distances to every password used in the login attempts so far. For example, suppose the passwords used so far are 33 and 44. For a new password 88, the safety distance between 33 and 88 is 33, and the safety distance between 44 and 88 is 22, so the safety level of 88 is 22.

To delay the hacker from finding out the password as long as possible, Hyangbin wants to change the administrator account password currently in use so that its safety level is as high as possible. Find the safety level of the password with the highest safety level.

Input

The first line contains the integer NN, the maximum value of the administrator account password. (0≤N≤1 000 0000 \leq N \leq 1\ 000\ 000)

The second line contains the integer MM, the number of passwords used in the login attempts. (1≤M≤100 0001 \leq M \leq 100\ 000)

The third line contains the integers p1,p2,⋯ ,pMp_1, p_2, \cdots, p_M, the passwords used in the login attempts. (0≤pi≤N0 \leq p_i \leq N)

Output

Print the safety level of the password with the highest safety level.

Examples1

  1. Example 1

    Input
    10
    2
    3 4
    
    Expected output
    2