QOJ.ac

QOJ

Limite de temps : 1 s Limite de mémoire : 512 MB Points totaux : 100

#8162. Reading

Statistiques

Zayin is a student who loves reading.

Recently, Zayin received a book with $n$ chapters. Each chapter $i$ has a requirement: she must have read at least $a_i$ other chapters to gain enough wisdom to understand this chapter.

Every day, Zayin starts reading the book from the beginning to the end. For chapters she cannot yet understand (due to the requirement) or chapters she has already read, Zayin skips them that day.

Now, Zayin wants to know the minimum number of days required to finish reading all $n$ chapters.

Input

The first line contains two integers $d, n$, representing the test case number and the number of chapters.

The second line contains $n$ integers $a_i$ ($0 \le a_i < n$), representing the requirements.

Output

Output a single integer representing the minimum number of days required.

If Zayin cannot finish reading all $n$ chapters, output $-1$.

Examples

Input 1

1 10
3 4 0 6 1 1 0 8 6 3

Output 1

2

Constraints

This problem uses subtask-based testing.

For all test data, it is guaranteed that $1 \le n \le 5 \times 10^5$ and $0 \le a_i < n$.

  • Subtask 1 (10%): $1 \le n \le 10, d = 1$.
  • Subtask 2 (10%): $1 \le n \le 500, d = 2$.
  • Subtask 3 (20%): $1 \le n \le 5000, 3 \le d \le 4$.
  • Subtask 4 (20%): $1 \le n \le 10^5, 5 \le d \le 6$.
  • Subtask 5 (40%): $1 \le n \le 5 \times 10^5, 7 \le d \le 10$.

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.