This page is still under construction.

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

K-summary

Time limit0.5sMemory limit64 MB

Summary
Given segment lengths K_i, count how many array positions are pinned down by all the K_i-summaries.
Level

Hard8 of 10

Topics
Math, Number theory, Prefix sum, Implementation
Solved
No attempts yet

Problem

An unknown array xx holds NN integers. The KK-summary of that array is what you get by cutting the array into segments of length KK from the front and adding up the elements of each segment. If NN is not divisible by KK, the last segment is shorter than KK.

In other words, the elements of the KK-summary are, in order, x[1]+⋯+x[K]x[1] + \cdots + x[K], x[K+1]+⋯+x[2K]x[K+1] + \cdots + x[2K], and so on, and only the last sum, the one that contains x[N]x[N], can have fewer than KK terms. For example, the 5-summary of an array of 13 elements has three elements: the sum of elements 1 to 5, the sum of elements 6 to 10, and the sum of elements 11 to 13.

One KK-summary alone is not enough to recover the elements of the original array. If you know the summaries for several different values of KK, some elements are pinned down to a single value. You are given the length NN and the numbers K1,K2,…,KMK_1, K_2, \ldots, K_M. Write a program that computes how many elements of the original array are uniquely determined when all KiK_i-summaries are known. That count does not depend on the values written in the summaries.

Input

The first line contains the array length NN and the number of summaries MM. (3≤N≤1093 \le N \le 10^9, 1≤M≤101 \le M \le 10)

The second line contains distinct integers K1,K2,…,KMK_1, K_2, \ldots, K_M. (2≤Ki<N2 \le K_i < N)

Output

Print the number of elements that are uniquely determined.

Hint

In the first example, only x[3]x[3] can be determined.

In the second example, x[3]x[3] and x[4]x[4] can be determined.

Examples3

  1. Example 1

    Input
    3 1
    2
    
    Expected output
    1
    
  2. Example 2

    Input
    6 2
    2 3
    
    Expected output
    2
    
  3. Example 3

    Input
    123456789 3
    5 6 9
    
    Expected output
    10973937