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 (Python):

import re
import math
from collections import defaultdict
import itertools
from copy import deepcopy
import random
from heapq import heappop,heappush
import time
import os
import queue
import sys
import datetime
from functools import lru_cache
readline=sys.stdin.readline
sys.setrecursionlimit(2000)

alphabet="abcdefghijklmnopqrstuvwxyz"
mod=int(10**9+7)
inf=int(10**20)
def yn(b):
    if b:
        print("yes")
    else:
        print("no")
def Yn(b):
    if b:
        print("Yes")
    else:
        print("No")
def YN(b):
    if b:
        print("YES")
    else:
        print("NO")
class union_find():
    def __init__(self,n):
        self.n=n
        self.P=[a for a in range(N)]
        self.rank=[0]*n
 
    def find(self,x):
        if(x!=self.P[x]):self.P[x]=self.find(self.P[x])
        return self.P[x]
 
    def same(self,x,y):
        return self.find(x)==self.find(y)
 
    def link(self,x,y):
        if self.rank[x]<self.rank[y]:
            self.P[x]=y
        elif self.rank[y]<self.rank[x]:
            self.P[y]=x
        else:
            self.P[x]=y
            self.rank[y]+=1
 
    def unite(self,x,y):
        self.link(self.find(x),self.find(y))
 
    def size(self):
        S=set()
        for a in range(self.n):
            S.add(self.find(a))
        return len(S)
def is_power(a,b):
    now=b
    while now<a:
        now*=b
    if now==a:return True
    else:return False
def bin_(num,size):
    A=[0]*size
    for a in range(size):
        if (num>>(size-a-1))&1==1:
            A[a]=1
        else:
            A[a]=0
    return A
def get_facs(n,mod_=0):
    A=[1]*(n+1)
    for a in range(2,len(A)):
        A[a]=A[a-1]*a
        if(mod>0):A[a]%=mod_
    return A
def comb(n,r,mod,fac):
    if(n-r<0):return 0
    return (fac[n]*pow(fac[n-r],mod-2,mod)*pow(fac[r],mod-2,mod))%mod
def next_comb(num,size):
    x=num&(-num)
    y=num+x
    z=num&(~y)
    z//=x
    z=z>>1
    num=(y|z)
    if(num>=(1<<size)):return False
    else:
        return num
def get_primes(n,type="int"):
    A=[True]*(n+1)
    A[0]=False
    A[1]=False
    for a in range(2,n+1):
        if A[a]:
            for b in range(a*2,n+1,a):
                A[b]=False
    if(type=="bool"):return A
    B=[]
    for a in range(n+1):
        if(A[a]):B.append(a)
    return B
def is_prime(num):
    if(num<=2):return False
    i=2
    while i*i<=num:
       if(num%i==0):return False
       i+=1
    return True
def ifelse(a,b,c):
    if a:return b
    else:return  c
def join(A,c=" "):
    n=len(A)
    A=list(map(str,A))
    s=""
    for a in range(n):
        s+=A[a]
        if(a<n-1):s+=c
    return s
def factorize(n,type_="dict"):
    b = 2
    list_ = []
    while b * b <= n:
        while n % b == 0:
            n //= b
            list_.append(b)
        b+=1
    if n > 1:list_.append(n)
    if type_=="dict":
        dic={}
        for a in list_:
            if a in dic:
                dic[a]+=1
            else:
                dic[a]=1
        return dic
    elif type_=="list":
        return list_
    else:
        return None
def floor_(n,x=1):
    return x*(n//x)
def ceil_(n,x=1):
    return x*((n+x-1)//x)

def main():
    n,m=map(int,input().split())
    A=list(map(int,input().split()))
    s=sum(A)
    if n>=s:
        print(n-s)
    else:
        print(-1)
main()

Solution (Python):
N, M = map(int, input().split())
A = list(map(int, input().split()))
print(max(N-sum(A), -1))

Solution (Python):
N , M  = map ( int , input().strip().split(" ") ) ;
arr  = list (  map ( int , input().strip().split(" ") ) ) ;
r = N - sum ( arr ) ;

r = -1 if r< 0 else r ; 
print ( r ) ;

Solution (Python):
n, m = map(int, input().split())
a = map(int, input().split())
a_sum = sum(a)
ans = n - a_sum
if ans >= 0:
    print(ans)
else:
    print("-1")

Solution (Python):
N, M = [int(n) for n in input().split()]
A = sum([int(n) for n in input().split()])
print(N-A if A <= N else -1)

Solution (Python):
N, M = [int(i) for i in input().split()]
Am = [int(i) for i in input().split()]
days = sum(Am)
print(max(N - days, -1))

Solution (Python):
N,K=[int(s) for s in input().split()]
ls=[int(s) for s in input().split()]
print(max([N-sum(ls),-1]))

Solution (Python):



import sys

s2nn = lambda s: [int(c) for c in s.split(' ')]
ss2nn = lambda ss: [int(s) for s in list(ss)]
ss2nnn = lambda ss: [s2nn(s) for s in list(ss)]
i2s = lambda: sys.stdin.readline().rstrip()
i2n = lambda: int(i2s())
i2nn = lambda: s2nn(i2s())
ii2ss = lambda n: [i2s() for _ in range(n)]
ii2nn = lambda n: ss2nn(ii2ss(n))
ii2nnn = lambda n: ss2nnn(ii2ss(n))

def main():
    N, M = i2nn()
    A = i2nn()
    hw = sum(A)
    play = N - hw
    if play >= 0:
        print(play)
    else:
        print(-1)
    return

main()

Solution (Python):
N, M = map(int, input().split())
A = list(map(int, input().split()))

res = sum(A) - N

if res>0:
    print(-1)
else:
    print(-1*res)

Solution (Python):


iim = lambda: map(int, input().rstrip().split())

def resolve():
    N, M = iim()
    A = sum(iim())

    ans = N - A
    if ans < 0:
        ans = -1
    print(ans)

if __name__ == "__main__":
    resolve()

Solution (Python):
a,b=map(int,input().split())
l=list(map(int,input().split()))
if a-sum(l)>=0:
    print(a-sum(l))
else:
    print(-1)

Solution (Python):
n,m=map(int,input().split())
a=list(map(int,input().split()))

if sum(a) > n:
  print("-1")
else:
  print(n - sum(a))

Solution (Python):
n, m = map(int, input().split())
a = map(int, input().split())

ans = n - sum(a)

if ans < 0:
    print(-1)
else:
    print(ans)

Solution (Python):
n,m = map(int,input().split())
a_list = list(map(int,input().split()))

if n-sum(a_list) >= 0:
    print(n-sum(a_list))
    
else:
    print(-1)

Solution (Python):
from sys import stdin


def main():

    N, _ = [int(x) for x in stdin.readline().rstrip().split()]

    a_lists = [int(x) for x in stdin.readline().rstrip().split()]

    sum_ = sum(a_lists)

    if N >= sum_:
        print(N-sum_)
    else:
        print(-1)


if __name__ == "__main__":
    main()

Solution (Python):

n=list(map(int,input().split()))
L=list(map(int,input().split()))
print(n[0]-sum(L) if n[0]-sum(L)>=0 else "-1")

Solution (Python):


N,M = list(map(int, input().split()))
A = list(map(int, input().split()))

ans = N-sum(A)

if ans < 0:
    print(-1)
else:
    print(ans)

Solution (Python):
n, m = map(int,input().split())

a_list = list(map(int,input().split()))

r = n-sum(a_list)
print(r if r >= 0 else -1)

Solution (Python):
N, M = map(int, input().split())
A = [int(x) for x in input().split()]
day = N - sum(A)
if day < 0:
    print(-1)
else:
    print(day)

Solution (Python):
N, M = map(int,input().split())
AA = list(map(int,input().split()))
if sum(AA)>N:
    print(-1)
else:
    print(N-sum(AA))

Solution (Python):
n, m = map(int, input().split())
*a, = map(int, input().split())
ans = -1
if n >= sum(a):
    ans = n - sum(a)
print(ans)

Solution (Python):
N, M = map(int, input().split())
A = list(map(int, input().split()))
home = sum(A)
if N >= home:
    print(N - home)
else:
    print(-1)

Solution (Python):


''' 
------------------------
author : iiou16
------------------------
'''

def main():
    N, M = list(map(int, input().split()))
    A = list(map(int, input().split()))

    ss = sum(A)
    if ss > N:
        print(-1)
    else:
        print(N - ss)


if __name__ == '__main__':
    main()

Solution (Python):
n, m = map(int, input().split())
a = list(map(int, input().split()))
a_sum = sum(a)

if n < a_sum:
    print(-1)
else:
    print(n - a_sum)

Solution (Python):
N,M=map(int,input().split())
A=list(map(int,input().split()))

S=N-sum(A)

if S<0:
  print(-1)
else:
  print(S)

Solution (Python):
N, M = map(int,input().split())
a = list(map(int, input().split()))
if N < sum(a):
	print('-1')
else:
	print(N - sum(a))

Solution (Python):




def main():
  N, _ = map(int, input().split())
  S = sum(map(int, input().split()))

  if S > N:
    print(-1)
  else:
    print(N - S)


if __name__ == '__main__':
  main()

Solution (Python):
n, m = map(int, input().split())
s = sum(map(int, input().split()))
if n-s < 0:
    print(-1)
else:
    print(n-s)

Solution (Python):
n,m=map(int,input().split())
a=list(map(int,input().split()))
A=sum(a)
if A<=n:
  print(n-A)
else:
  print(-1)

Solution (Python):
n, m = map(int,input().split())
ans=0
ans+=sum(list(map(int,input().split())))
if n-ans<0:
	print(-1)
else:
	print(n-ans)

Solution (Python):


n, m = map(int, input().split())
A = list(map(int, input().split()))
ans = n - sum(A)
if ans < 0:
	print(-1)
else:
	print(ans)

Solution (Python):
N, M =map(int,input().split())
a = list(map(int, input().split(' ')))
j = sum(a)
print(max(N-j,-1))

Solution (Python):
import sys
input = sys.stdin.readline

import math

def main():
    n,m = map(int, input().strip().split())
    a_li = list(map(int, input().strip().split()))

    if n - sum(a_li) < 0:
        print(-1)
    else:
        print(n - sum(a_li))


if __name__ == '__main__':
    main()

Solution (Python):
N, M = [int(x) for x in input().split()]
A = sum(int(x) for x in input().split())

print(max(N-A, -1))

Solution (Python):
def resolve():
    n, m = map(int, input().split())
    a = list(map(int, input().split()))
    b=sum(a)
    if b>n:
        print(-1)
    else:
        print(n-b)
resolve()

Solution (Python):
n,m=map(int,input().split())
a=list(map(int,input().split()))
if n>=sum(a):
  print(n-sum(a))
else:
  print(-1)

Solution (Python):
N, M = map(int, input().split())
A = list(map(int, input().split()))
for i in range(M):
    N -= A[i]
if N>=0:
    print(N)
elif N < 0:
    print(-1)

Solution (Python):

n, m = map(int, input().split())
a = list(map(int, input().split()))
if sum(a) > n:
    print(-1)
    exit()
print(n - sum(a))

Solution (Python):
n, m = map(int, input().split(" "))
a_list = list(map(int, input().split(" ")))

print(max(n - sum(a_list), -1))

Solution (Python):
N, M = map(int, input().split())
A = list(map(int, input().split()))

S = sum(A)

print(N-S if N-S>=0 else -1)

Solution (Python):
n,m= map(int,input().split(' '))
arr= list(map(int,input().split(' ')))
print(max(-1,n-sum(arr)))

Solution (Python):
def resolve():
    N, M = map(int, input().split())
    SA = sum(tuple(map(int, input().split())))
    if SA > N:
        print(-1)
    else:
        print(N-SA)

if __name__ == '__main__':
    resolve()

Solution (Python):
N, M = map(int, input().split())
A = list(map(int, input().split()))

playdays = N - sum(A)

if playdays < 0:
    print(-1)
else:
    print(playdays)

Solution (Python):
n, m = map(int, input().split())
a = list(map(int, input().split()))
if n < sum(a):
	print(-1)
else:
	print(n-sum(a))

Solution (Python):
N,M = map(int,input().split())
la = list(map(int,input().split()))
print(max(N-sum(la),-1))

Solution (Python):
def main():
    N , M = map(int, input().split())
    A_list = [A for A in input().split()]
    A_list = list(map(int, A_list))

    total = sum(A_list)
    day = N - total

    if total > N :
        print("-1")
    else :
        print(day)


if __name__ == '__main__':
    main()

Solution (Python):
from sys import stdin
import sys


N, M = [int(x) for x in stdin.readline().rstrip().split()]



A = list(map(int, input().split()))
if N-sum(A) >= 0:
    print(N-sum(A))
else:
    print("-1")

Solution (Python):
n, m = map(int, input().split())
ans = n - sum(map(int, input().split()))

print(-1) if ans < 0 else print(ans)

Solution (Python):
import numpy as np

n,m = map(int, input().split())
a = list(map(int, input().split()))

rtn = n - np.sum(a)
if rtn < 0:
    rtn = -1
print(rtn)

Solution (Python):
N, M = map(int, input().split())
A_list=[int(i) for i in input().split()]
A_sum=sum(A_list)
if N-A_sum>0:
  print(N-A_sum)
elif N-A_sum==0:
  print('0')
else:
  print('-1')

Solution (Python):
N,M = map(int,input().split())
A = list(map(int,input().split()))
if N-sum(A) >= 0:
    print(N-sum(A))
else:
    print(-1)

Solution (Python):


n,m=map(int, input().split())
a=list(map(int, input().split()))

ans=n-sum(a)
if ans<0:
    print(-1)
else:
    print(ans)

Solution (Python):
n,m=map(int,input().split())
A=[int(i) for i in input().split()]
days_needed=sum(A)
if(days_needed>n):
    print(-1)
else:
    print(n-days_needed)

Solution (Python):
n,m = map(int,input().split())
a = list(map(int,input().split()))

print(n-sum(a) if n-sum(a) >= 0 else -1)

Solution (Python):
import math



N,M= map(int, input().split())
A = list(map(int, input().split()))






if N-sum(A)>= 0:
    print(N-sum(A))
else:
    print(-1)

Solution (Python):
n,m =map(int,input().split())
A = list(map(int,input().split()))

s = sum(A)

if s > n:
    print("-1")
else:
    print(n-s)

Solution (Python):
n,m = map(int,input().split())
a = list(map(int,input().split()))

b = sum(a)

if b > n:
    print(-1)
else:
    print(n-b)

Solution (Python):
import sys
n, m = map(int, sys.stdin.readline().strip().split())
A = list(map(int, sys.stdin.readline().strip().split()))

ans = n - sum(A)

if ans < 0:
    ans = -1

print(ans)

Solution (Python):
n,m= map(int, input().split())
a= list(map(int, input().split()))

for i in range(m):
    n-=a[i]

if n>=0:
    print(n)
else:
    print(-1)

Solution (Python):
N, M = map(int, input().split())

a_list = list(map(int, input().split()))

cnt_day = sum(a_list)

if N >= cnt_day:
    print(N-cnt_day)
else:
    print(-1)

Solution (Python):
s = input().split(" ")
N = int(s[0])
M = s[1]
s = input().split(" ")
A = []
sum = 0
for w in s:
    A.append(int(w))
    sum += int(w)

if sum <= N:
    print(N - sum)
else:
    print(-1)

Solution (Python):
N, M = map(int, input().split())
A = list(map(int, input().split()))
if (N - sum(A) >= 0):
    print(N-sum(A))
else:
    print("-1")

Solution (Python):
def b():
    N, M = map(int, input().split())
    A = list(map(int, input().split()))

    play = N - sum(A)
    if play < 0:
        print(-1)
    else:
        print(play)



if __name__ == "__main__":
    b()

Solution (Python):
from __future__ import print_function

import sys

import re
import array
import copy
import functools
import operator

import math
import string
import fractions
from fractions import Fraction
from fractions import gcd

import collections
import itertools
import bisect

import random
import time

import heapq
from heapq import heappush
from heapq import heappop
from heapq import heappushpop
from heapq import heapify
from heapq import heapreplace
from queue import PriorityQueue as pq
from queue import Queue

from itertools import accumulate

from collections import deque
from collections import Counter

from operator import mul
from functools import reduce

input = sys.stdin.readline


def eprint(*args, **kwargs):
    print(*args, file=sys.stderr, **kwargs)
    return


def lcm(n, m):
    return int(n * m / gcd(n, m))


def coprimize(p, q):
    common = fractions.gcd(p, q)
    return (p // common, q // common)


def combinations_count(n, r):
    r = min(r, n - r)
    numer = reduce(mul, range(n, n - r, -1), 1)
    denom = reduce(mul, range(1, r + 1), 1)
    return numer // denom


def find_gcd(list_l):
    x = reduce(gcd, list_l)
    return x


def main():
    n,m = map(int,input().strip().split())
    a = list(map(int, input().strip().split()))

    print(max(n-sum(a),-1))


if __name__ == '__main__':
    main()

Solution (Python):
N, M = (int(i) for i in input().split())  
A = [int(i) for i in input().split()] 

sub = N - sum(A)

if sub < 0:
  print(-1)
else:
  print(sub)

Solution (Python):
N, M = map(int,input().split())
A = list(map(int,input().split()))

if N - sum(A) >= 0:
    print(N - sum(A))
else:
    print(-1)

Solution (Python):
n,m=list(map(int,input().split(" ")))
a=list(map(int,input().split(" ")))
b=sum(a)
if n-b>=0:
  print(n-b)
else:
  print(-1)

Solution (Python):
N,M = map(int,input().split())
A_list = list(map(int,input().split()))

A_sum = sum(A_list)
if A_sum <= N:
    print(N-A_sum)
else:
    print(-1)

Solution (Python):
N, M = map(int, input().split())
A = list(map(int, input().split()))

leisure = N - sum(A)
if leisure < 0:
  print("-1")
else:
  print(leisure)

Solution (Python):
N,M = map(int,input().split())
a = list(map(int,input().split()))

ans = N - sum(a)
print(ans if ans>=0 else -1)

Solution (Python):
n, m = [int(x) for x in input().split()]

a = [int(x) for x in input().split()]

if n -sum(a) < 0:
  print(-1)
  quit()
print(n-sum(a))

Solution (Python):

N,M = list(map(int , input().split()))
A = list(map(int , input().split()))
S = sum(A)
if N >= S:
    print(N-S)
else:
    print("-1")

Solution (Python):

n, m = map(int, input().split())
a = list(map(int, input().split()))
study = sum(a)
if n < study:
    print(-1)
else:
    print(n-study)

Solution (Python):
n,m = map(int,input().split())
a = list(map(int,input().split()))

for ai in a:
    n -= ai
if n >= 0:
    print(n)
else:
    print(-1)

Solution (Python):
days, num_homewrok = [int(i) for i in input().split()]
homeworks = [int(i) for i in input().split()]
sum_homeworks = sum(homeworks)

ans = days - sum_homeworks if days >= sum_homeworks else -1

print(ans)

Solution (Python):
INT_MAX=10**18+7
MOD=10**9+7
def INPUT():return list(int(i) for i in input().split())
def LIST_1D_ARRAY(n):return [0 for _ in range(n)]
def LIST_2D_ARRAY(m,n):return [[0 for _ in range(n)]for _ in range(m)]

n,m=INPUT()
A=INPUT()
sum=0
for ele in A:
    sum+=ele
if n>=sum:
    print(n-sum)
else:
    print(-1)

Solution (Python):
n,m=map(int,input().split())
a=list(map(int,input().split()))
if sum(a)>n:
  print(-1)
else:
  print(n-sum(a))

Solution (Python):
n,m=map(int,input().split())
a=list(map(int,input().split()))
s=sum(a)
if n-s<0:print(-1)
else:print(n-s)

Solution (Python):



N, M = list(map(int, input().split()))
A = list(map(int, input().split()))


def main():
    s = sum(A)
    ans = max(-1, N - s)
    print(ans)


if __name__ == "__main__":
    main()

Solution (Python):
import sys
from math import ceil, floor
from collections import deque, Counter, defaultdict
from fractions import gcd
input = lambda: sys.stdin.readline().rstrip()

def eprint(s):
    sys.stderr.write('DEBUG: {}'.format(s))
    return

def main():
    n,m = map(int, input().split())
    As = list(map(int, input().split()))
    sm = sum(As)

    if (n-sm < 0):
        print(-1)
    else:
        print(n-sm)
    
    return

if __name__ == '__main__':
    main()

Solution (Python):
a = list(map(int,input().split()))
b = list(map(int,input().split()))

if sum(b)<=a[0]:
    print(a[0]-sum(b))
else:
    print(-1)

Solution (Python):
s = list(map(int, input().split()))
a = list(map(int, input().split()))
n=s[0]
m=s[1]
for i in range (m):
    n-=a[i]
if n<0:
    print(-1)
else:
    print(n)

Solution (Python):
N , M = map(int, input().split())
A = list(map(int, input().split()))
if sum(A) > N:
    print(-1)
else:
    print(N - sum(A))

Solution (Python):
N, M = map(int, input().split())
A = list(map(int, input().split()))
work = N-sum(A)
if work < 0:
    work = -1
print(work)

Solution (Python):
import math
N,M=map(int,input().split())
A=list(map(int,input().split()))
if N-sum(A)>=0:
    print(N-sum(A))
else:
    print(-1)

Solution (Python):
def i1str():
    return input()


def istrs(n=None):
    if n is None:
        return input().split()
    a = []
    for _ in range(n):
        a.append(istrs())
    return a


def i1num():
    return int(input())


def inums(n=None):
    if n is None:
        return list(map(int, input().split()))
    a = []
    for _ in range(n):
        a.append(inums())
    return a


def ostrs(l, sp=" "):
    print(sp.join(l))


def onums(l, sp=" "):
    print(sp.join(map(str, l)))


def solve(n, a):
    res = n-sum(a)
    if res < 0:
        res = -1
    return res


if __name__ == "__main__":
    n, m = inums()
    a = inums()
    print(solve(n, a))

Solution (Python):
N,M = map(int,input().split())
a = list(map(int,input().split()))

a.sort(reverse=True)
b = 1
su = 0
for i in range(M):
  su += a[i]
  if su > N:
    b = -1
    
  
print(N - su if b > 0 else '-1')

Solution (Python):
n, m = map(int, input().split())
a = list(map(int, input().split()))

ans = n - sum(a)
print(ans if ans >= 0 else -1)

Solution (Python):

def resolve():
    n,m = map(int, input().split())
    a = list(map(int, input().split()))
    if sum(a) > n:
        print(-1)
        return
    print(n - sum(a))

if __name__ == '__main__':
    resolve()

Solution (Python):
n,m=map(int,input().split())
A=list(map(int,input().split()))
a=sum(A)
if a>n:
    print(-1)
else:
    print(n-a)

Solution (Python):
N, M = map(int, input().split())
A = list(map(int, input().split()))

ans = N-sum(A)
if ans<0:
    print("-1")
else:
    print(ans)

Solution (Python):
n, m = map(int, input().split())
lst = list(map(int, input().split()))
if sum(lst) > n:
    print(-1)
else:
    print(n - sum(lst))

Solution (Python):
n,m=map(int,input().split())
a=list(map(int,input().split()))
print(max(-1,n-sum(a)))

Solution (Python):
N, M = map(int, input().split())
A = [int(a) for a in input().split()]

result = N - sum(A)

if result >= 0:
  print(result)
else:
  print(-1)

Solution (Python):
N, M = map(int, input().split())
A = list(map(int, input().split()))
Asum = sum(A)
print(max(-1, N - Asum))

Solution (Python):
N, M = map(int, input().split())
A = list(map(int, input().split()))
if sum(A) > N:
    print(-1)
else:
    print(N-sum(A))

Solution (Python):
N, M = map(int, input().split())
A = list(map(int, input().split()))

SUM = sum(A)

if N - SUM < 0:
    print(-1)
else:
    print(N - SUM)

Solution (Python):
def solve(n, m, arr):
    ans = n - sum(arr)
    if ans >= 0:
        print(ans)
    else:
        print(-1)
if __name__ == "__main__":
    n, m = map(int, input().split(' '))
    arr = [int(s) for s in list(input().split())]
    solve(n, m, arr)

Solution (Python):
N, M = map(int, input().split())

A = list(map(int, input().split()))

day = N - sum(A)

if day < 0:
  print(-1)
else:
  print(day)

Solution (Python):
n,m=map(int,input().split())
A=list(map(int,input().split()))
print(n-sum(A) if n-sum(A)>=0 else -1)

Solution (Python):
n,m=map(int,input().split())
a=[int(i) for i in input().split()]
print(n-sum(a) if n>=sum(a) else -1)

Solution (Python):
n,m=map(int,input().split())
a=list(map(int,input().split()))
ans=n-sum(a)

print(ans if ans>=0 else -1)

Solution (Python):
n, m = map(int, input().split())
A = list(map(int, input().split()))
rem = n-sum(A)

print(max(rem, -1))

Solution (Python):




def main():
    N, M = map(int, input().split())
    A = list(map(int, input().split()))

    hw = sum(A)

    if N >= hw:
        print(N-hw)
    else:
        print(-1)


if __name__ == '__main__':
    main()

Solution (Python):
import sys,math
def input():
    return sys.stdin.readline()[:-1]
N,M = map(int,input().split(' '))
l = list(map(int, input().split()))

ANS = 0

for i in range(M):
    ANS += l[i]
if ANS>N:
    print(-1)
else:
    print(N-ANS)

Solution (Python):
N,M= map(int,input().split())
A = list(map(int,input().split()))
print(max(N-sum(A),-1))

Solution (Python):
M,N= map(int,(input().split()))
a = list(map(int,input().split()))
for i in range(len(a)):
  M -= a[i]
if(M>=0):
  print(M)
else:
  print(-1)

Solution (Python):

N, M = map(int, input().split())
A = list(map(int, input().split()))

if N >= sum(A):
    print(N-sum(A))
else:
    print('-1')

Solution (Python):
N,M=map(int,input().split())
A=[int(i) for i in input().split()]
print(N-sum(A) if N-sum(A)>=0 else -1)

Solution (Python):
n,m=map(int,input().split())
a=list(map(int,input().split()))
d=sum(a)
if d>n:
    print(-1)
else:
    print(n-d)

Solution (Python):
from collections import defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue,copy,time
sys.setrecursionlimit(10**8)
input = sys.stdin.readline
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inp():
    '''
    一つの整数
    '''
    return int(input())
def inpl():
    '''
    一行に複数の整数
    '''
    return list(map(int, input().split()))
def inpl_str():
    '''
    一行に複数の文字
    '''
    return list(input().split())

n, m = inpl()
a = inpl()
if n - sum(a) < 0:
    print("-1")
else:
    print(n-sum(a))

Solution (Python):
def main():
    N, M = map(int, input().split())
    A = list(map(int, input().split()))

    
    

    max = sum(A)
    ans = N - max
    if ans < 0:
        print(-1)
    else:
        print(ans)


if __name__ == '__main__':
    main()

Solution (Python):
N,M=map(int,input().split())
A=list(map(int,input().split()))
ans=N
for i in range(0,M):
    ans-=A[i]
if ans>=0:
    print(ans)
else:
    print(-1)

Solution (Python):
def main():
    n,m = map(int, input().split())
    a = list(map(int, input().split()))
    if n - sum(a) >= 0:
        print(n-sum(a))
    else:
        print(-1)

if __name__ == '__main__':
    main()

Solution (Python):
n,m = map(int,input().split())
l = list(map(int,input().split()))
print(max(n-sum(l),-1))

Solution (Python):
N, M = map(int, input().split())
dl = list(map(int, input().split()))

ans = N - sum(dl)

if ans >= 0:
  print(ans)
else:
  print('-1')

Solution (Python):
n, m = map(int, input().split())
a = list(map(int, input().split()))
ans = n - sum(a)
if ans < 0:
    ans = -1
print(ans)

Solution (Python):
def main():
    n, m = [int(x) for x in input().split()]
    l = [int(x) for x in input().split()]
    play = n - sum(l)
    if play < 0:
        return - 1
    else:
        return play


if __name__ == '__main__':
    print(main())

Solution (Python):
n, m = map(int, input().split())
hw = sum(list(map(int, input().split())))
if n - hw < 0:
    print(-1)
else:
    print(n-hw)

Solution (Python):

N,M=map(int,input().split())
A=list(map(int,input().split()))

for i in range(M):
    N-=A[i]

ans=max(-1,N)

print(ans)

Solution (Python):
N, M = map(int, input().split())
A = list(map(int, input().split(" ")))
val = N-sum(A)
if val < 0:
    print(-1)
else :
    print(N-sum(A))

Solution (Python):
N,M = map(int,(input().split()))
A = list(map(int,(input().split())))
if N - sum(A) >= 0:
    print(N-sum(A))
else:
    print(-1)

Solution (Python):
N,M = map(int,input().split())
A=list(map(int,input().split()))

if sum(A)>N:
	print("-1")
else:
	print(N-sum(A))

Solution (Python):
N, M = map(int, input().split())
A = list(map(int, input().split()))

print(max(N - sum(A), -1))

Solution (Python):
def input_int():
    return map(int, input().split())

def one_int():
    return int(input())

def one_str():
    return input()

def many_int():
    return list(map(int, input().split()))

N,M = input_int()
A = many_int()

sumA=sum(A)
if sumA<=N:
    print(N-sumA)
else:
    print(-1)

Solution (Python):
N,M = map(int,input().split())
A=list(map(int,input().split()))

if N < sum(A):
    print('-1')
else:
    print(N - sum(A))

Solution (Python):
n,m = map(int, input().split())
a = list(map(int, input().split()))

if n>=sum(a):
    print(n-sum(a))
else:
    print(-1)

Solution (Python):
n, m = input().split()
As = input().split()
suma = 0
for a in As:
    suma += int(a)
res = int(n) - suma
if res < 0:
    print(-1)
else:
    print(res)

Solution (Python):
n, m = map(int, input().split())
aList = list(map(int, input().split()))
aSum = sum(aList)
if n < aSum:
  print(-1)
else:
  print(n - aSum)

Solution (Python):
n,m=map(int,input().split())
l=list(map(int,input().split()))
for i in l:
  n-=i
if n>=0:
  print(n)
else:
  print("-1")

Solution (Python):
n, m = tuple(map(int, input().split()))
a = list(map(int, input().split()))

a_sum = sum(a)
if a_sum > n:
    print(-1)
else:
    print(n-a_sum)

Solution (Python):
n,m = map(int,input().split())
a = list(map(int,input().split()))

ans = n - sum(a)

if(ans >= 0):
    print(ans)
else:
    print(-1)

Solution (Python):
N,M = map(int,input().split(" "))
somme=0
suite = input().split(" ")
for i in range(M):
  somme+=int(suite[i])
if somme>N:
  print(-1)
else:
  print(N-somme)

Solution (Python):
N, M = map(int,input().split())
A = list(map(int, input().split()))

if N < sum(A):
    print(-1)
else:
    print(N - sum(A))

Solution (Python):
N, M = map(int, input().split())

costs = list(map(int, input().split()))
totalCosts = sum(costs)
free = N - totalCosts
print(max(free, -1))

Solution (Python):
N, M = map(int, input().strip().split())
s = sum(map(int, input().strip().split()))

if N >= s:
  print(N - s)
else:
  print(-1)

Solution (Python):
day,m = list(map(int,input().split()))
listA = list(map(int,input().split()))
listA = sum(listA)
if day >= listA:
    print(day-listA)
else:
    print("-1")

Solution (Python):
n,m=map(int,input().split())
print(max(-1,n-sum(list(map(int,input().split())))))

Solution (Python):
n,m=map(int,input().split())
a=list(map(int,input().split()))
if n-sum(a)<0:
    print("-1")
else:
    print(n-sum(a))

Solution (Python):
N, M = map(int, input().split())
As = list(map(int, input().split()))
print(max(-1, N - sum(As)))

Solution (Python):
import bisect,collections,copy,heapq,itertools,math,operator,string
def I(): return int(input())
def S(): return input()
def LI(): return list(map(int,input().split()))
def LS(): return list(input().split())

N,M = LI()
A = LI()
for x in A:
    N -= x
print(N if N>=0 else -1)

Solution (Python):
N, M = [int(i.strip()) for i in input().split(' ')]
A = [int(i.strip()) for i in input().split(' ')]

S = sum(A)
ans = N-S
if ans < 0:
    print(-1)
else:
    print(ans)

Solution (Python):
n,m = [int(e) for e in input().split()]
a = [int(e) for e in input().split()]
for i in range(m):
    n -= a[i]
if n < 0:
    print(-1)
else:
    print(n)

Solution (Python):
n, m = map(int, input().split())
a_i = list(map(int, input().split()))
sum = sum(a_i)
if sum <= n: print(n - sum)
else: print(-1)

Solution (Python):
import numpy as np
import math
import itertools

N, M = map(int, input().split())
A = list(map(int, input().split()))

ans = N -sum(A)

if ans < 0:
    ans = -1

print(ans)

Solution (Python):
n, m = map(int, input().split())
a = sum(list(map(int, input().split())))

if a > n:
    print(-1)
else :
    print(n - a)

Solution (Python):
def resolve():
    '''
    code here
    '''
    N, M = [int(item) for item in input().split()]
    A_list = [int(item) for item in input().split()]

    all_sum = sum(A_list)

    if N >= all_sum:
        print(N - all_sum)
    else:
        print(-1)

if __name__ == "__main__":
    resolve()

Solution (Python):
if __name__ == "__main__":
    n, m = map(int, input().split())
    a = list(map(int, input().split()))

    ans = n

    for aa in a:
        ans -= aa
        if ans < 0:
            print(-1)
            exit()

    print(ans)