B - Homework Editorial /

Time Limit: 2 sec / Memory Limit: 1024 MB

配点 : 200

問題文

高橋君の夏休みは N 日間です。

夏休みの宿題が M 個出されており、i 番目の宿題をやるには A_i 日間かかります。

複数の宿題を同じ日にやることはできず、また、宿題をやる日には遊ぶことができません。

夏休み中に全ての宿題を終わらせるとき、最大何日間遊ぶことができますか?

ただし、夏休み中に全ての宿題を終わらせることができないときは、かわりに -1 を出力してください。

制約

  • 1 \leq N \leq 10^6
  • 1 \leq M \leq 10^4
  • 1 \leq A_i \leq 10^4

入力

入力は以下の形式で標準入力から与えられる。

N M
A_1 ... A_M

出力

高橋君が遊ぶことのできる日数、または、-1 を出力せよ。


入力例 1

41 2
5 6

出力例 1

30

例えば、最初の 5 日間で 1 番目の宿題をやり、その後 30 日間遊んで、最後の 6 日間で 2 番目の宿題をやることで、30 日間遊ぶことができます。


入力例 2

10 2
5 6

出力例 2

-1

宿題を終わらせることができません。


入力例 3

11 2
5 6

出力例 3

0

宿題を終わらせることはできますが、遊ぶことはできません。


入力例 4

314 15
9 26 5 35 8 9 79 3 23 8 46 2 6 43 3

出力例 4

9

Score : 200 points

Problem Statement

Takahashi has N days of summer vacation.

His teacher gave him M summer assignments. It will take A_i days for him to do the i-th assignment.

He cannot do multiple assignments on the same day, or hang out on a day he does an assignment.

What is the maximum number of days Takahashi can hang out during the vacation if he finishes all the assignments during this vacation?

If Takahashi cannot finish all the assignments during the vacation, print -1 instead.

Constraints

  • 1 \leq N \leq 10^6
  • 1 \leq M \leq 10^4
  • 1 \leq A_i \leq 10^4

Input

Input is given from Standard Input in the following format:

N M
A_1 ... A_M

Output

Print the maximum number of days Takahashi can hang out during the vacation, or -1.


Sample Input 1

41 2
5 6

Sample Output 1

30

For example, he can do the first assignment on the first 5 days, hang out on the next 30 days, and do the second assignment on the last 6 days of the vacation. In this way, he can safely spend 30 days hanging out.


Sample Input 2

10 2
5 6

Sample Output 2

-1

He cannot finish his assignments.


Sample Input 3

11 2
5 6

Sample Output 3

0

He can finish his assignments, but he will have no time to hang out.


Sample Input 4

314 15
9 26 5 35 8 9 79 3 23 8 46 2 6 43 3

Sample Output 4

9