Under construction

Still being built. Things may change

Opening Day 2

Interview

Time limit1sMemory limit256 MB

Summary
Given wok sizes, each cooking uses one or two distinct woks and produces the sum of their sizes; find the minimum number of cookings summing to exactly N.
Level

Medium5 of 10

Topics
Dynamic programming, Greedy, Math, Implementation
Solved
No attempts yet

Problem

Haebin loves jajangmyeon so much that he opened a Chinese restaurant that sells nothing else. He is ambidextrous, so a single cooking can use up to two woks at the same time.

A wok

Haebin hates waste, so every wok he uses is filled to its exact capacity. Cooking with one wok of size ss produces exactly ss bowls, and cooking with two woks of sizes ss and tt at the same time produces exactly s+ts+t bowls. A single cooking cannot use the same wok twice, but if Haebin owns two or more woks of the same size, he can use two of them together. Every wok is available again for the next cooking.

The order is NN bowls, and the bowls produced by all of the cookings must add up to exactly NN. Write a program that finds the smallest number of cookings that fills the order.

Input

The first line has the number of bowls ordered NN and the number of woks Haebin owns MM, separated by a space. (1≤N≤100001 \le N \le 10000, 1≤M≤10001 \le M \le 1000)

The second line has the wok sizes S1,S2,…,SMS_1, S_2, \dots, S_M, separated by spaces. (1≤Si≤N1 \le S_i \le N) Haebin may own several woks of the same size.

Output

Print the minimum number of cookings needed to fill the whole order. If no combination of cookings produces exactly NN bowls, print -1.

Hint

Consider making 6 bowls with one wok of size 1 and one wok of size 3. Cook 3 bowls in the size 3 wok, then cook 3 more bowls in the same wok, and 6 bowls are done in two cookings. A wok can be reused in every later cooking, but only two different woks can go into one cooking.

Examples2

  1. Example 1

    Input
    5 2
    1 3
    
    Expected output
    2
    
  2. Example 2

    Input
    6 2
    1 3
    
    Expected output
    2