Under construction

Still being built. Things may change

Megavirus

Time limit1sMemory limit128 MB

Summary
Given k and n viruses from generation k in a binary tree, find the deepest generation whose node is an ancestor of all given viruses.
Level

Medium4 of 10

Topics
Tree, Bit manipulation, Math, Brute force
Solved
No attempts yet

Problem

A hacker built a megavirus. Every copy of the virus has its own number, and the very first copy is numbered 00. Every minute a new generation of viruses is created. A virus numbered ii in generation kk produces two children in generation k+1k + 1, numbered 2⋅i2 \cdot i and 2⋅i+12 \cdot i + 1. These two newly created viruses 2⋅i2 \cdot i and 2⋅i+12 \cdot i + 1 are called the children of virus ii from generation kk. Virus vv together with its children, its children's children, and so on are called the descendants of vv (virus vv is also counted among its own descendants), and vv is called their ancestor; in particular, every virus is an ancestor of itself. Generation numbers start from 00. The viruses that live in each generation are:

  • generation 00: virus 00
  • generation 11: viruses 00, 11
  • generation 22: viruses 00, 11, 22, 33
  • generation 33: viruses 00, 11, 22, 33, 44, 55, 66, 77
  • ...

Given one generation number and the numbers of several viruses from that generation, compute the largest generation number that contains a common ancestor of all the given viruses, and print it.

Input

The first line contains two integers kk and nn separated by a space. kk (1≤k≤5121 \le k \le 512) is the generation number, and nn (1≤n≤1501 \le n \le 150) is the number of viruses to read. Each of the next nn lines contains the number of one virus. Since every virus belongs to generation kk, each number is an integer between 00 and 2k−12^k - 1 inclusive.

Output

Print, on a single line, the largest generation number that contains a common ancestor of all the viruses.

Examples2

  1. Example 1

    Input
    2 2
    1
    2
    
    Expected output
    0
    
  2. Example 2

    Input
    3 2
    4
    5
    
    Expected output
    2