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)

/**
 * code generated by RHelper
 * More info: https://github.com/mkc1370/RHelper
 * @author 
 */

using Task.BHomework;

using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Text;

namespace Task.BHomework
{
    public class BHomework
    {
        public void Solve()
        {
            var n = CINL;
            var m = CINL;
            var a = CINVL(m);
            var sum = n - a.Sum();
            COUT(sum < 0 ? -1 : sum);
        }
        
        private readonly StringReader cin;
        private readonly StringWriter cout;
        private readonly Scanner scanner;

        public BHomework(StringReader cin, StringWriter cout)
        {
            this.cin = cin;
            this.cout = cout;
            scanner = new Scanner(cin);
        }

        private long CINL => scanner.Long();
        private double CIND => scanner.Double();
        private string CINS => scanner.String();
        private static IEnumerable<T> Repeat<T>(T v, long n) => Enumerable.Repeat(v, (int)n);
        private List<long> CINVL(long n) => Repeat(0, n).Select(_ => CINL).ToList();
        private List<double> CINVD(long n) => Repeat(0, n).Select(_ => CIND).ToList();
        private List<string> CINVS(long n) => Repeat(0, n).Select(_ => CINS).ToList();

        private void COUT(object o) => cout.WriteLine(o);
        
        private void Yes(bool value) => cout.WriteLine(value ? "Yes" : "No");
        private void YES(bool value) => cout.WriteLine(value ? "YES" : "NO");
        private void Possible(bool value) => cout.WriteLine(value ? "Possible" : "Impossible");
        private void POSSIBLE(bool value) => cout.WriteLine(value ? "POSSIBLE" : "IMPOSSIBLE");
    }

    public static class MathEx
    {
        // O (log N)
        public static long Gcd(long n, long m)
        {
            n = Math.Abs(n);
            m = Math.Abs(m);
            while (n != 0)
            {
                m %= n;
                if (m == 0) return n;
                n %= m;
            }

            return m;
        }

        // O (log N)
        public static long Lcm(long n, long m)
        {
            return n / Gcd(n, m) * m;
        }

        // O (N log log N)
        public static bool[] GetPrimeList(int max, List<int> primes = null)
        {
            var isPrime = new bool[max + 1];
            for (var i = 2; i < isPrime.Length; i++) isPrime[i] = true;
            for (var i = 2; i * i <= max; i++)
                if (!isPrime[i]) continue;
                else
                    for (var j = i * i; j <= max; j += i)
                        isPrime[j] = false;
            if (primes != null)
                for (var i = 0; i <= max; i++)
                    if (isPrime[i])
                        primes.Add(i);

            return isPrime;
        }

        // O (N)
        public static T Max<T>(params T[] array) where T : IComparable
        {
            var max = array[0];
            foreach (var value in array)
            {
                if (max.CompareTo(value) < 0)
                    max = value;
            }

            return max;
        }

        // O (N)
        public static T Min<T>(params T[] array) where T : IComparable
        {
            var min = array[0];
            foreach (var value in array)
            {
                if (min.CompareTo(value) > 0)
                    min = value;
            }

            return min;
        }

        public static void Swap<T>(ref T lhs, ref T rhs)
        {
            var temp = lhs;
            lhs = rhs;
            rhs = temp;
        }
    }

    public class Scanner
    {
        public Scanner(StringReader stringReader)
        {
            this.stringReader = stringReader;
        }

        private readonly StringReader stringReader;
        private readonly char[] buffer = new char[1024];
        private int len, ptr;
        private bool isEof;

        private char Read()
        {
            if (isEof) throw new EndOfStreamException();
            if (ptr >= len)
            {
                ptr = 0;
                if ((len = stringReader.Read(buffer, 0, 1024)) <= 0)
                {
                    isEof = true;
                    return '\0';
                }
            }

            return buffer[ptr++];
        }

        public char Char()
        {
            char b;
            do b = Read();
            while (b < 33 || 126 < b);
            return b;
        }

        public string String()
        {
            var sb = new StringBuilder();
            for (char b = Char(); b >= 33 && b <= 126; b = Read())
                sb.Append(b);
            return sb.ToString();
        }

        public long Long()
        {
            long ret = 0;
            char b;
            var ng = false;
            do b = Read();
            while (b != '-' && (b < '0' || '9' < b));
            if (b == '-')
            {
                ng = true;
                b = Read();
            }

            for (;; b = Read())
            {
                if (b < '0' || '9' < b)
                    return ng ? -ret : ret;
                else ret = ret * 10 + b - '0';
            }
        }

        public double Double()
        {
            return double.Parse(String(), CultureInfo.InvariantCulture);
        }
    }

    public struct ModInt
    {
        public const int Mod = 1000000007;
        private const long Positivizer = ((long)Mod) << 31;
        private long data;
        public ModInt(long data) { if ((this.data = data % Mod) < 0) this.data += Mod; }
        public static implicit operator long(ModInt modInt) => modInt.data;
        public static implicit operator ModInt(long val) => new ModInt(val);
        public static ModInt operator +(ModInt a, int b) => new ModInt() { data = (a.data + b + Positivizer) % Mod };
        public static ModInt operator +(ModInt a, long b) => new ModInt(a.data + b);
        public static ModInt operator +(ModInt a, ModInt b) { long res = a.data + b.data; return new ModInt() { data = res >= Mod ? res - Mod : res }; }
        public static ModInt operator -(ModInt a, int b) => new ModInt() { data = (a.data - b + Positivizer) % Mod };
        public static ModInt operator -(ModInt a, long b) => new ModInt(a.data - b);
        public static ModInt operator -(ModInt a, ModInt b) { long res = a.data - b.data; return new ModInt() { data = res < 0 ? res + Mod : res }; }
        public static ModInt operator *(ModInt a, int b) => new ModInt(a.data * b);
        public static ModInt operator *(ModInt a, long b) => a * new ModInt(b);
        public static ModInt operator *(ModInt a, ModInt b) => new ModInt() { data = a.data * b.data % Mod };
        public static ModInt operator /(ModInt a, ModInt b) => new ModInt() { data = a.data * GetInverse(b) % Mod };
        public static bool operator ==(ModInt a, ModInt b) => a.data == b.data;
        public static bool operator !=(ModInt a, ModInt b) => a.data != b.data;
        public override string ToString() => data.ToString();
        public override bool Equals(object obj) => obj != null && (ModInt)obj == this;
        public override int GetHashCode() => (int)data;

        private static long GetInverse(long a)
        {
            long div, p = Mod, x1 = 1, y1 = 0, x2 = 0, y2 = 1;
            while (true)
            {
                if (p == 1) return x2 + Mod; div = a / p; x1 -= x2 * div; y1 -= y2 * div; a %= p;
                if (a == 1) return x1 + Mod; div = p / a; x2 -= x1 * div; y2 -= y1 * div; p %= a;
            }
        }
    }
}


public class Output
{
	public static void Main()
	{
		var reader = new System.IO.StringReader(Console.In.ReadToEnd());
		var writer = new System.IO.StringWriter();
		var solver = new BHomework(reader, writer);
		solver.Solve();
		System.Console.Write(writer.GetStringBuilder().ToString());
	}
}