This page is still under construction.

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

Strongbox

Time limit1sMemory limit128 MB

Summary
Given that only the last of k tried dial positions opens a safe, find the maximum possible number of opening positions consistent with the closure rule (x+y) mod n.
Level

Medium7 of 10

Topics
Number theory, Math, Brute force
Solved
No attempts yet

Problem

Byteasar tests and certifies anti-burglary devices. He has just received a new kind of strongbox to test: a combinatorial safe. It is opened with a rotary dial, just like an ordinary combination safe, but the way it opens is different.

The dial can be set to nn different positions, numbered 00 to n−1n-1. Some of these positions open the safe and the others do not. The set of opening positions has the following combinatorial property, which gives the safe its name: if xx and yy are both opening positions, then (x+y) mod n(x + y) \bmod n is an opening position as well. This holds for x=yx = y too.

Byteasar tried kk distinct positions m1,m2,…,mkm_1, m_2, \ldots, m_k. The first k−1k-1 of them, m1,m2,…,mk−1m_1, m_2, \ldots, m_{k-1}, did not open the safe; only the last one, mkm_k, did. He does not intend to try any of the remaining positions. Using only what he has learned from the positions he tried, determine the maximum possible number of positions that open the safe.

Input

The first line contains two integers nn and kk separated by a single space, where 1≤k≤250 0001 \le k \le 250\,000 and k≤n≤1014k \le n \le 10^{14}.

The second line contains kk distinct integers m1,m2,…,mkm_1, m_2, \ldots, m_k separated by single spaces, where 0≤mi<n0 \le m_i < n.

The input is guaranteed to correspond to some combinatorial safe consistent with the description above: there exists a safe that positions m1,…,mk−1m_1, \ldots, m_{k-1} do not open and position mkm_k does.

Output

Print a single integer: the maximum number of dial positions that can open the safe.

Examples3

  1. Example 1

    Input
    42 5
    28 31 10 38 24
    
    Expected output
    14
    
  2. Example 2

    Input
    100 1
    7
    
    Expected output
    100
    
  3. Example 3

    Input
    12 4
    1 5 7 9
    
    Expected output
    4