Problem:
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

Solution in C# (.NET Core 3.1.201) (judge verdict: Accepted)

using System;
using System.Collections;
using System.Collections.Generic;

namespace 練習問題
{
    class Program {
        static void Main(string[] args) {
            List<int> pattern = new List<int>();
            List<int> zikan = new List<int>();
            int n = 0;
            int m = 0;
            int judge = 0;
            string[] input;
            var sw = new System.Diagnostics.Stopwatch();
            debug Debug = new debug();
            if (args.Length == 0){
                Debug.FlagFalse();
                string[] nminput = Console.ReadLine().Split(' ');
                n = int.Parse(nminput[0]);
                m = int.Parse(nminput[1]);
                // c = int.Parse(Console.ReadLine());
                // string d = Console.ReadLine();
                input = Console.ReadLine().Split(' ');
            } else {
                Debug.FlagTrue();
                if (args[0] == "1"){
                    n = 41;
                    m = 2;
                    input = new string[2] {"5","6"};
                } else if (args[0] == "2"){
                    n = 10;
                    m = 2;
                    input = new string[2] {"5","6"};
                } else if (args [0] == "3"){
                    n = 11;
                    m = 2;
                    input = new string[2] {"5","6"};
                } else if (args[0] == "4"){
                    n = 314;
                    m = 15;
                    input = new string[15] {"9" ,"26" ,"5" ,"35" ,"8" ,"9" ,"79" ,"3" ,"23" ,"8","46","2","6","43","3"};
                } else {
                    n = 1;
                    m = 1;
                    input = new string[1] {"1"};
                }
            }
            sw.Start(); //2秒以内ですねスタート
            for (int i = 0; i < m; i++) {
                zikan.Add(int.Parse(input[i]));
            }
            for (int i = 0; i < zikan.Count; i++) {
                judge += zikan[i];
            }
            if (judge <= n){
                Console.WriteLine(n - judge);
            } else {
                Console.WriteLine(-1);
            }
            sw.Stop();
            TimeSpan ts = sw.Elapsed;
            // Console.WriteLine($"{ts}");
        }
        
        static int intPow(int target,int kaisu){
            int startTarget = target;
            for (int i = 1; i < kaisu; i++)
            {
                target *= startTarget;
            }
            return target;
        }

        static void bubble_sort(List<List<int>> a) {
            int count=0;
            for (int i = 0; i < a.Count; i++) {
                for (int j = 0; j < a.Count-i-1; j++) {
                    // if (a[j] == a[a.Count - 1]){
                    //     continue;
                    // }
                    count++;
                    if (a[j][1] > a[j+1][1]){
                        int localsave = 0;
                        localsave = a[j+1][1];
                        a[j+1][1] = a[j][1];
                        a[j][1] = localsave;
                        localsave = a[j][0];
                        a[j][0] = a[j+1][0];
                        a[j+1][0] = localsave;
                    }
                }
                //debug(a,"途中" + i);
            }
            // debug(a,"result");
            //Console.WriteLine("回数"+count);
            for (int i = 0; i < a.Count; i++)
            {
                Console.WriteLine(a[i][0]+" "+a[i][1]);
            }
        }
        /* 標準入力と標準出力が使えるかのチェック
        static void echo() {
            string echotest = Console.ReadLine();
            Console.WriteLine(echotest);
        }

        static void HelloWorld(){
            Console.WriteLine("Hello World!");
        }
        */
    }

    public class debug{ //宣言時は、「 debug Debug = new debug(); 」推奨
        bool debug_flag = true;
        public void Log(string str){
            if (debug_flag == true){
                Console.WriteLine(str);
            }
        }
        public void Log(int str){
            if (debug_flag == true){
                Console.WriteLine(str);
            }
        }
        public void Log(float str){
            if (debug_flag == true){
                Console.WriteLine(str);
            }
        }
        public void Log(object obj){
            if (debug_flag == true){
                Console.WriteLine(obj);
            }
        }

        public void Log(int[] arr){
            if (debug_flag == true){
                Console.WriteLine(string.Join(",", arr));
            }
        }
        public void Log(string[] arr){
            if (debug_flag == true){
                Console.WriteLine(string.Join(",", arr));
            }
        }
        public void Log(List<int> arr){
            if (debug_flag == true){
                string shuturyoku = "";
                for (int i = 0; i < arr.Count; i++) {
                    shuturyoku += arr[i] + ",";
                }
                Console.WriteLine(shuturyoku.TrimEnd(','));
            }
        }

        public void Log(List<string> arr){
            if (debug_flag == true){
                string shuturyoku = "";
                for (int i = 0; i < arr.Count; i++) {
                    shuturyoku += arr[i] + ",";
                }
                Console.WriteLine(shuturyoku.TrimEnd(','));
            }
        }

        public void Log(List<float> arr){
            if (debug_flag == true){
                string shuturyoku = "";
                for (int i = 0; i < arr.Count; i++) {
                    shuturyoku += arr[i] + ",";
                }
                Console.WriteLine(shuturyoku.TrimEnd(','));
            }
        }
        public void Log(){
            if (debug_flag == true){
                Console.WriteLine("アタイイレナサイ");
            }
        }
        public void FlagFalse(){
            debug_flag = false;
        }
        public void FlagTrue(){
            debug_flag = true;
        }
    }
}