Under construction

Still being built. Things may change

Test Taking

Time limit1sMemory limit128 MB

Summary
Given N questions and a set of possible true-counts, choose a true/false answer key maximizing the worst-case number of correct answers.
Level

Hard8 of 10

Topics
Math, Greedy, Implementation, Sorting
Solved
No attempts yet

Problem

Farmer John must take his annual farming-license test, which has NN (1≤N≤1,000,0001 \le N \le 1{,}000{,}000) true/false questions. After a dismal result last year, his cow Bessie wants to help.

Bessie has inside information: the number of questions whose correct answer is 'true' is guaranteed to be one of t1,t2,…,tKt_1, t_2, \dots, t_K (0≤ti≤N0 \le t_i \le N; 0≤K≤10,0000 \le K \le 10{,}000). She does not know the correct answer to any individual question — only the possible totals of 'true' answers.

Farmer John writes an answer ('true' or 'false') for every question. Because he knows nothing about any specific question, an adversary may choose both the actual number of 'true' answers (one of Bessie's values) and exactly which questions those are, so as to make Farmer John's score as low as possible. Farmer John wants to pick his answers so that the number of correct answers he is guaranteed — no matter what — is as large as possible.

For example, take N=6N = 6 with the count of 'true' answers being 00 or 33. If Farmer John marks every question 'false', he gets all 66 correct when the count is 00 and 33 correct when the count is 33, so at least 33 are guaranteed. If instead he guesses that some 33 answers are 'true', the adversary can make all 33 of those wrong, dropping his guarantee to 00. Marking everything 'false' is therefore better, guaranteeing 33.

Given Bessie's information, determine the largest number of correct answers Farmer John can guarantee by playing optimally.

Input

  • Line 1: two space-separated integers NN and KK.
  • Lines 2…K+12 \dots K+1: line i+1i+1 contains a single integer tit_i.

(When K=0K = 0 there are no further lines.)

Output

  • A single integer: the best score Farmer John is guaranteed to achieve.

Examples2

  1. Example 1

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

    Input
    100 1
    40
    
    Expected output
    60