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++ (GCC 9.2.1) (judge verdict: Accepted)

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
// using namespace __gnu_pbds;
using namespace std;
// typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;
// typedef tree<int,int,less<int>,rb_tree_tag,tree_order_statistics_node_update> indexed_map;
#define ll long long
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define si size()
#define bk back()
#define popb pop_back()
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define endl "\n"
#define lb lower_bound
#define ub upper_bound
#define emp empty()
#define beg begin()
#define en end()
#define ump unordered_map
#define forl(i,a,n) for(int i=a;i<n;i++)
#define rfor(i,n,a) for(int i=n;i>=a;i--)
#define fore(i,a,n) for(int i=a;i<=n;i++)
#define len length()
#define ld long double
//use (__int128)to extend ll range
// cout<<__builtin_popcountll(10)<<endl; //number of 1
// cout<<__builtin_parityll(6)<<endl;//(number of 1)mod(2)
// cout<<__builtin_clzll(10)<<endl;//number of zeros at beginning (64 bit rep) 
// cout<<__builtin_ctzll(8)<<endl;//number of zeros at end (64 bit rep) 
const long double PI=3.14159265358979323846;
double doINF = 1.0/0.0 ;
ostream_iterator <int> outp(cout," ");
inline ll modadd(ll n,ll m,ll mod){
    ll sum = (((n%mod)+(m%mod))%mod+mod)%mod;
    return sum;
} 
inline ll modsub(ll n,ll m, ll mod){
    ll diff = (((n%mod)-m+mod)%mod+mod)%mod;
    return diff;
}
inline ll modpro(ll n,ll m,ll mod){
    ll pro = ((((n+mod)%mod)*((m+mod)%mod)+mod)%mod+mod)%mod;
    return pro;
}
inline ll pow(int x,int y){
    ll res = 1;
    while (y > 0) {
        if (y & 1)
            res = res * x;
        y = y >> 1;
        x = x * x;
    }
    return res;
}
inline ll powmod(ll x,ll y,ll mod){
    ll res = 1;
    while (y > 0) {
        if (y & 1)
            res = modpro(res , x,mod);
        y = y >> 1;
        x = modpro(x , x,mod);
    }
    return res;
}
long long power(long long a,long long b)
{
    if(b==0) return 1;
    long long p = power(a, b/2);
    if(b&1) return p*p*a;
    else return p*p;
}
ll min(ll a, ll b){
if(a>b){
    return b;
}
return a;
}

ll max(ll a, ll b){
if(a>b){
    return a;
}else return b;
}

bool pairdec(const pair<int,int> &a,  
            const pair<int,int> &b) 
{ 		if(a.fi!=b.fi)
        return (a.fi> b.fi);
        else return a.se>b.se;  
} 
ll power(ll x, ll y, ll mod) 
{ 
    ll res = 1; 
    x = (x+mod)%mod; 
    while (y > 0) { 
        if (y & 1) 
            res =modpro(res,x,mod); 

        y = y >> 1;
        x =modpro(x,x,mod); 
    } 
    return res; 
} 


ll modInverse(ll a, ll mod) 
{ 
    return  powmod(a, mod - 2, mod); 
} 
ll modFact(ll n, ll mod) 
{ 
    if (n >=mod) return 0; 

    ll result = 1; 
    for (ll i = 1; i <= n; i++) 
        result = (result * i) %mod; 

    return result; 
} 
//ncrmodp
ll modcomb(ll n,ll r, ll mod) 
{ 
if (r==0) return 1; 
ll val1=modFact(n,mod);
ll val2=modInverse(modFact(r,mod),mod);
ll val3=modInverse(modFact(n-r,mod),mod);
ll val4=modpro(val1,val2,mod);
return modpro(val4,val3,mod);
} 
//modular inverse for 1 to n(Extended Euclid Algo)
void modInverse2(ll n,ll mod)
{
    ll dp[n+1];
    dp[0]=dp[1]=1;
    fore(i,2,n)
    {
        dp[i]=dp[mod%i]*((mod-mod/i)%mod);
    }
}
//cout<<setprecision(9)<<fixed<<sum<<endl; --- precision for double numbers
bool comp(const pair<int,int>pia,const pair<int,int>pib)
{
    if(pia.fi==pib.fi) return pia.se<=pib.se;
    else return pia.fi<pib.fi;
}
int main()
{
   ll num,n;
   cin>>num>>n;
   ll arr[n];
   ll sum=0;
   forl(i,0,n)
   {
       cin>>arr[i];
       sum+=arr[i];
   }
   if(sum>num) cout<<-1<<endl;
   else cout<<num-sum<<endl;

}