PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#GD0000231. Phân công công việc (Schedule Management)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

2 lộ trình

Phân công công việc (Schedule Management)

Schedule Management

Source: Codeforces

Version: Phuoc Hung OJ Extended

Problem Statement

There are nn workers and mm tasks. Task ii has one proficient worker numbered aia_i. Assign every task to exactly one worker.

A worker completes a task in 11 hour if proficient in it and otherwise needs 22 hours. Workers process at most one task at a time but operate in parallel, starting at time 00.

Find the earliest possible time when all tasks are finished.

Input

  • The first line contains n,mn,m.
  • The next line contains mm integers a1,…,ama_1,\ldots,a_m, identifying the proficient worker for each task.

Output

Print the minimum completion time in hours.

Subtasks

  • Subtask 1 (20 points): 1≤n≤201\le n\le 20; n≤m≤100n\le m\le 100; 1≤ai≤n1\le a_i\le n.
  • Subtask 2 (30 points): 1≤n≤20001\le n\le 2000; n≤m≤10000n\le m\le 10000; 1≤ai≤n1\le a_i\le n.
  • Subtask 3 (50 points): 1≤n≤2000001\le n\le 200000; n≤m≤2⋅105n\le m\le 2\cdot 10^5; 1≤ai≤n1\le a_i\le n.

Examples

Input

2 4
1 1 1 1

Output

3

Explanation

Worker 11 is proficient in all four tasks; worker 22 is proficient in none. Within 33 hours, worker 11 handles three tasks and worker 22 handles the last in 22 hours. Within 22 hours, they can handle only two plus one tasks, so the minimum is 33.