Under construction

Still being built. Things may change

Rainbow Bowl Ranges

Time limit2sMemory limit2048 MB

Summary
Given n bowls in a circle and m colors with c_i balls each, place each color as a contiguous arc to maximize the number of maximal runs where every color appears exactly once.
Level

Medium7 of 10

Topics
Math, Greedy, Sorting
Solved
No attempts yet

Problem

There are nn bowls arranged in a circle.

There are many balls of various colors. There are mm different colors, and there are c_ic\_i balls of the ii-th color.

Distribute all the balls into the bowls. For each color, choose a contiguous range of bowls of size c_ic\_i and put one ball of that color into each bowl in the range. A contiguous range is a set of consecutive bowls around the circle. Ranges of different colors may overlap.

A bowl is rainbow if it contains exactly one ball of each color. A rainbow bowl range is a contiguous run of rainbow bowls that cannot be extended by adding another rainbow bowl.

Arrange the balls to maximize the number of rainbow bowl ranges. Given nn and the number of balls of each color, find the maximum number of rainbow bowl ranges that can be formed.

Input

The first line contains two integers nn (2≤n≤109)(2 \le n \le 10^9) and mm (1≤m≤105)(1 \le m \le 10^5). Each of the next mm lines contains a single integer c_ic\_i (1≤c_i≤n)(1 \le c\_i \le n).

Output

Print a single integer, the maximum number of rainbow bowl ranges that can be formed.

Examples2

  1. Example 1

    Input
    4 2
    3
    3
    
    Expected output
    2
    
  2. Example 2

    Input
    10 11
    3
    1
    4
    1
    5
    9
    2
    6
    5
    3
    5
    
    Expected output
    1