Under construction

Still being built. Things may change

Alien Socks

Interview

Time limit1sMemory limit1024 MB

Summary
Given counts of socks in s colors, find the smallest number of socks to draw to guarantee k socks of one color, or -1 if impossible.
Level

Easy3 of 10

Topics
Math, Greedy, Array
Solved
No attempts yet

Problem

An alien spaceship has landed in Bitland. The aliens were completely charmed by Bitland's fashionable socks. Because each alien has kk legs, they bought a huge number of socks in many different colors.

The alien Bronius keeps socks of ss different colors in his drawer, and he knows exactly how many socks of each color he has. Every morning Bronius pulls socks out of the drawer one at a time without looking, and he keeps going until he holds kk socks of the same color.

This morning Bronius is in a great hurry and wants to know the minimum number of socks he must pull out so that he is guaranteed to hold at least kk socks of one color.

Input

The first line contains two positive integers: Bronius's number of legs kk and the number of sock colors in the drawer ss.

The second line contains ss positive integers nin_i, where nin_i is the number of socks of the ii-th color in the drawer.

Output

Output a single positive integer — the minimum number of socks Bronius must pull out. If it is impossible for Bronius to ever collect kk socks of one color, output −1-1.

Constraints

  • 1≤k≤1 0001 \le k \le 1\,000
  • 1≤s≤1 0001 \le s \le 1\,000
  • 1≤ni≤1 0001 \le n_i \le 1\,000 for all ii.

Examples2

  1. Example 1

    Input
    5 3
    3 6 8
    
    Expected output
    12
    
  2. Example 2

    Input
    10 3
    5 6 8
    
    Expected output
    -1