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)

/*
@Author: Ayush Shah :)
@Institution: BIT Mesra :)
*/

#include<bits/stdc++.h>
using namespace std;

#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds;
// find_by_order(k)  returns iterator to kth element starting from 0;
// order_of_key(k) returns count of elements strictly smaller than k;


template <typename T>
using min_pq = priority_queue<T, vector<T>, greater<T>>;

#define deb(x) cout << #x << " " << x << endl;
#define deb1(x, y) cout << #x << " " << x << " " << #y << " " << y << endl;
#define deb2(x, y, z) cout << #x << " " << x << " " << #y << " " << y << " " << #z << " " << z << endl;
#define fast  ios_base::sync_with_stdio(false), cin.tie(NULL) , cout.tie(NULL)
#define test int T1; cin >> T1; while(T1--)
#define ui  unsigned int
#define ll  long long int 
#define ld  long double
#define pb  push_back
#define mp  make_pair
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define vll vector<ll>
#define pi pair<int, int>
#define pll pair<ll, ll>
#define vpll vector< pll >
#define bigint int64_t
#define mod 1000000007
#define endl '\n'

#define forn(i,a,n) for(ll (i) = a;(i) <= (n); (i)++)
#define forr(i,a,n) for(ll (i) = n; (i) >= (a); (i)--)

template <typename... T>
void read(T&...args) {
     ((cin >> args), ...);
}

template<typename T> void dout(string name, T arg) {
  cout << name << " = " << arg << endl;
}

template<typename T1, typename... T2> void dout(string names, T1 arg, T2... args) {
  cout << names.substr(0, names.find(',')) << " = " << arg << " | ";
  dout(names.substr(names.find(',') + 2), args...);
}

#ifndef ONLINE_JUDGE
  #define debug(...) dout(#__VA_ARGS__, __VA_ARGS__)
#else
  #define debug(...) 42
#endif

typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

/////////////////////////////////////////////***NUMBER THEORY***///////////////////////////////////////////////////////////////

vll seive;
void Seive (ll N) {
    seive.resize(N+1);
    forn (i, 1, N)
    seive[i] = i;
    for (ll i = 4; i <= N; i += 2)
    seive[i] = 2;
    for (ll i = 3; i*i <= N; i++) {
        if (seive[i] == i) {
            for (ll j = i*i; j <= N; j += i) {
                if (seive[j] == j)
                seive[j] = i;
            }
        }
    }
}

ll Power(ll x, ll n){
    if(n==0)
    return 1;
    
    if(n%2)
    return x*Power(x*x, (n-1)/2);
    else
    return Power(x*x, n/2);
}

ll Power_with_mod(ll x, ll n, ll m = mod){
    if(n==0)
    return 1;
    
    if(n%2)
    return (x*Power_with_mod((x*x)%m, (n-1)/2))%m;
    else
    return Power_with_mod((x*x)%m, n/2);
}

ll gcd(ll a, ll b){
    if(b == 0)
    return a;

    return gcd(b, a%b);
}

ll x, y, d;
void extended_euclid(ll a, ll b){
    if(b == 0){
        x = 1;
        y = 0;
        d = a;
    }
    else{
        extended_euclid(b, a%b);
        ll temp = x;
        x = y;
        y = temp - (a/b)*y;
    }
}

ll mod_inverse(ll a, ll m = mod){
    extended_euclid(a, m);
    return((x+m)%m);
}

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

template<typename T>
class DSU{
    public:
      T parent [200005];
      T size [200005];
      void init(T x){
          parent[x] = x;
          size[x] = 1;
      }
      T root(T x){
          if(parent[x] == x)
          return x;
          return parent[x] = root(parent[x]);
      }
      void Union(T x, T y){
          x = root(x);
          y = root(y);
          if(x != y){
              if(size[x] < size[y])
              swap(x, y);
              parent[y] = x;
              size[x] += size[y];
          }
      }
};

template <typename T>
class Segment_Tree{
    public:
      ll tree[4*100005];
      ll a[100005];
      void build(ll node, ll s, ll e){
          if(s == e)
          tree[node] = a[s];
          else{
              ll mid = (s + e)/2;
              build(2*node, s, mid);
              build(2*node+1, mid+1, e);
              tree[node] = (tree[2*node] | tree[2*node+1]);
          }
      }

      void update(ll node, ll s, ll e, ll pos, ll val){
          if(s == e){
              tree[node] = val;
              a[pos] = val;
          }
          else{
              ll mid = (s + e)/2;
              if(pos <= mid)
              update(2*node, s, mid, pos, val);
              else
              update(2*node+1, mid+1, e, pos, val);
              tree[node] = (tree[2*node] | tree[2*node+1]);
          }
      }

      ll query(ll node, ll s, ll e, ll l, ll r){
          if(s >= l && e <= r)
          return tree[node];
          else if(e < l || s > r)
          return 0ll;
          else{
              ll mid = (s + e)/2;
              ll left = query(2*node, s, mid, l, r);
              ll right = query(2*node+1, mid+1, e, l, r);
              return (left | right);
          }
      }
};  


int main()
{

     fast;

     #ifndef ONLINE_JUDGE
         freopen("/home/ayush/Desktop/CP/in.txt", "r", stdin);
         freopen("/home/ayush/Desktop/CP/out.txt", "w", stdout);
     #endif

//////////////////////////////////////////////////////////////////////////////////////////////////////////

     ll n, m;
     read(n, m);
     ll a[m];
     ll sum = 0;
     forn (i, 0, m-1) {
         read(a[i]);
         sum += a[i];
     }
     if (sum > n)
     cout << -1;
     else 
     cout << n - sum;

/////////////////////////////////////////////////////////////////////////////////////////////////////////

      #ifndef ONLINE_JUDGE
          cout << endl << "Time Elapsed: " << 1.0*clock() / CLOCKS_PER_SEC << " sec" <<endl;
      #endif

    return 0;

}