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

from sys import stdin
import sys


def nextLine(): return next(stdin)
def nextStrList(): return nextLine().split()
def nextIntList(): return [int(_) for _ in nextStrList()]

import numpy as np

def main():
	n,m=nextIntList()
	al=nextIntList()
	
	s=n-sum(al)
	if s<0:
		print("-1")
	else: print(s)
	
if __name__=="__main__":
	main()

Solution (Python):
N,M = input().split()
A = input().split()
 
S = 0
for i in range(int(M)):
    S += int(A[ i - 1 ])

if int(N) - S >= 0:
    print(int(N) - S)
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_list = list(map(int, input().split()))

a_sum = 0
for a in a_list:
    a_sum = a_sum + a

N = N - a_sum

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

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 = input()
list_a = A.split()

list_b = [int(i) for i in list_a]

sum_a = sum(list_b)

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()))
i = 0
total = 0
while i<M:
    total += A[i]
    i+=1
if N<total:
    print("-1")
else:
    print(N-total)

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(" "))
days = list(map(int, input().split(" ")))

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

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

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

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

sum = 0
for i in L:
    sum += i
    
if sum <= N:
    print( N - sum )
else:
    print(-1)

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

days = 0

for i in range(m):
    days += task[i]

if n >= days:
    print(n - days)
else:
    print(str(-1))

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

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

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

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

Solution (Python):


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

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

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

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

std = sum(A)

if std > N:
    print(-1)
else:
    ans = N - std
    print(ans)

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

Solution (Python):


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

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

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

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

s = 0

for i in range(m):
  s += a[i]

if s <= n:
  print(n - s)
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(-1)
else:
    print(n)

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

list = []

list[len(list):len(list)] = map(int, input().split())

sum = 0

for i in list:
  sum += i
  
if a-sum>=0:
  print(a-sum)
  
else:
  print(-1)

Solution (Python):
input_line = input().split(' ')
input_line = list(map(int, input_line))
input_assign = input().split(' ')
input_assign = list(map(int, input_assign))

len = input_line[0] - sum(input_assign)
if len < 0:
  print(-1)
else:
  print(len)

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

t = 0

for A in day_list:
    t += int(A)

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

Solution (Python):

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

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


if N >= x:
  y=N-x
  print(y)
else:
  print("-1")

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

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

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

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

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

Solution (Python):
a,b=map(int,input().split())
List=list(map(int,input().split()))
total=0
for i in range(b):
    total+=List[i]
    
if a>=total:
    print(int(a-total))
else:
    print('-1')

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

    count = 0
    for i in range(M):
        count = count + int(A[i])
    
    if N >= count:
        print(N-count)
    else:
        print(-1)
    

if __name__ == "__main__":
    main()

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

suma=sum(a)

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

Solution (Python):
def solve():
    N, M = map(int, input().split())
    hws = list(map(int, input().split()))
    for i in hws:
        N -= i
        if (N<0):
            print(-1)
            return

    print(N)

solve()

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

Solution (Python):
n, m = list(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()
A = list(map(int,input().split()))

sum_a = sum(A)

if int(N)-sum_a>=0:
  print(int(N)-sum_a)
else:
  print(-1)

Solution (Python):

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

Solution (Python):
def solve():
  n, m = map(int, input().split())
  a = list(map(int, input().split()))
  hoge = max(-1, n-sum(a))
  print(hoge)
  return 0
 
if __name__ == "__main__":
  solve()

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=input().split()
A = list(map(int, input().split())) 
N=int(N)
M=int(M)
t=N-sum(A)
if t>-1:
  print(t)
else:
  print(-1)

Solution (Python):
'''二分探索'''

'''デック'''

'''順列,組み合わせ,累積和,直積・forネスト'''

'''小数点以下切り捨て,小数点以下切り上げ,平方根,階乗,最大公約数'''

'''input 文字列は最後に\nを含む'''




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

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


if __name__ == '__main__':
    main()

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

work_time = sum(a)

answer = N - work_time

if answer < 0:
    answer = -1


print(answer)

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()))
answer=N-sum(A)
print("-1") if answer<0 else print(answer)

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

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

ans = sum(A)

if(N - ans < 0):
    print("-1")

else:
    print(N - ans)

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

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

for cost in a:
    n = n - cost

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

Solution (Python):


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

s = input()
t = s.split(" ")
sum = 0
for u in t:
    sum += int(u)
if sum > N:
    print(-1)
else:
    print(N-sum)

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

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

Solution (Python):
from heapq import heappush,heappop,heapify
from collections import deque,defaultdict,Counter
from itertools import permutations,combinations,groupby
import sys,bisect,string,math,time,functools,random
def Golf():*a,=map(int,open(0))
def I():return int(input())
def S_():return input()
def IS():return input().split()
def LS():return [i for i in input().split()]
def LI():return [int(i) for i in input().split()]
def LI_():return [int(i)-1 for i in input().split()]
def NI(n):return [int(input()) for i in range(n)]
def NI_(n):return [int(input())-1 for i in range(n)]
def StoLI():return [ord(i)-97 for i in input()]
def ItoS(n):return chr(n+97)
def LtoS(ls):return ''.join([chr(i+97) for i in ls])
def GI(V,E,Directed=False,index=0):
    org_inp=[];g=[[] for i in range(n)]
    for i in range(E):
        inp=LI();org_inp.append(inp)
        if index==0:inp[0]-=1;inp[1]-=1
        if len(inp)==2:
            a,b=inp;g[a].append(b)
            if not Directed:g[b].append(a)
        elif len(inp)==3:
            a,b,c=inp;aa=(inp[0],inp[2]);bb=(inp[1],inp[2]);g[a].append(bb)
            if not Directed:g[b].append(aa)
    return g,org_inp
def GGI(h,w,search=None,replacement_of_found='.',mp_def={'

    mp=[1]*(w+2);found={}
    for i in range(h):
        s=input()
        for char in search:
            if char in s:
                found[char]=((i+1)*(w+2)+s.index(char)+1)
                mp_def[char]=mp_def[replacement_of_found]
        mp+=[1]+[mp_def[j] for j in s]+[1]
    mp+=[1]*(w+2)
    return h+2,w+2,mp,found
def TI(n):return GI(n,n-1)
def bit_combination(k,n=2):
    rt=[]
    for tb in range(n**k):
        s=[tb//(n**bt)%n for bt in range(k)];rt+=[s]
    return rt
def show(*inp,end='\n'):
    if show_flg:print(*inp,end=end)

YN=['YES','NO'];Yn=['Yes','No']
mo=10**9+7
inf=float('inf')
l_alp=string.ascii_lowercase

input=lambda: sys.stdin.readline().rstrip()

class Comb:
    def __init__(self,n,mo=10**9+7):
        self.fac=[0]*(n+1)
        self.inv=[1]*(n+1)
        self.fac[0]=1
        self.fact(n)
        for i in range(1,n+1):
            self.fac[i]=i*self.fac[i-1]%mo
            self.inv[n]*=i
            self.inv[n]%=mo
        self.inv[n]=pow(self.inv[n],mo-2,mo)
        for i in range(1,n):
            self.inv[n-i]=self.inv[n-i+1]*(n-i+1)%mo
        return
    
    def fact(self,n):
        return self.fac[n]
        
    def invf(self,n):
        return self.inv[n]

    def comb(self,x,y):
        if y<0 or y>x:
            return 0
        return self.fac[x]*self.inv[x-y]*self.inv[y]%mo

show_flg=False
show_flg=True

ans=0

n,m=LI()
a=LI()

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

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

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

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

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

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):
data = input().split()
 
n = int(data[0])
m = int(data[1])
 
data = input().split()
 
homework = [int(s) for s in data]
day = 0
 
for i in homework:
  day += i

ans = n - day
if ans < 0:
  ans = -1

print(ans)

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

rem = N - sum(As)

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

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

value=sum(A)

if N-value>=0:
    print(N-value)

else:
    print(-1)

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

ruikeitime = sum(a_lst)

if n - ruikeitime < 0:
    print(-1)
else:
    print(n - ruikeitime)

Solution (Python):
b = list(map(int,input().split()))
a = list(map(int,input().split()))
n = int(b[0])
m = int(b[1])

total = 0
for i in a:
  total += i
  
if total<=n:
  print(n-total)
else:
  print("-1")

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

Solution (Python):
num = input().split()
n = int(num[0])
m = int(num[1])
a_list = input().split()
a_sum = 0
for a in a_list:
    a_sum += int(a)
    
if n>=a_sum:
    print(n-a_sum)
else:
    print(-1)

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

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

if n-S >=0:
  print(n-S)
if n-S<0:
  print(-1)

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

Solution (Python):
import sys
from operator import itemgetter
import collections
import math

def r(n, m, a):
    s = n - sum(a)
    if s < 0:
        s = -1
    return s


def main():
    input = sys.stdin.readline
    n, m = map(int, input().split())
    a = list(map(int, input().split()))
    print(r(n, m, a))

    
if __name__ == '__main__':
    main()

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

homework_days = 0
for day in A:
  homework_days += int(day)
  
if homework_days > int(N):
  print(-1)
else:
  print(int(N) - homework_days)

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

asum = sum(a)

ans = n-asum

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

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

sum_a = sum(a_list)
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()))
print(max(N-sum(A),-1))

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

Solution (Python):




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


sum = 0
for i in range(m):
    sum = sum + a[i]

ans = max(n - sum, -1)


print(ans)

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

Solution (Python):
from sys import setrecursionlimit, exit
setrecursionlimit(1000000000)

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

main()

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

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

rem = n - sum(days)

print(rem if rem >= 0 else '-1')

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

print(ans)

Solution (Python):


import sys
import math
import collections
import itertools
from inspect import currentframe
INF = 10 ** 10
MOD = 10 ** 9 + 7
def input() : return sys.stdin.readline().strip()
def gcd(x, y) : return y if x % y == 0 else gcd(y, x % y)
def lcm(x, y) : return (x * y) // gcd(x, y)
def I() : return int(input())
def LI() : return [int(x) for x in input().split()]
def RI(N) : return [int(input()) for _ in range(N)]
def LRI(N) : return [[int(x) for x in input().split()] for _ in range(N)]

N, M = LI()
A = LI()

aa = sum(A)

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

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

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

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




import sys
from io import StringIO
import unittest

def yn(b):
    print("Yes" if b==1 else "No")
    return

def resolve():
    readline=sys.stdin.readline

    n,m=map(int, readline().rstrip().split())
    arr=list(map(int, readline().rstrip().split()))
    aaa=sum(arr)

    n-=aaa
    if n<0:
        print(-1)
    else:
        print(n)
    
    
    

    return

if 'doTest' not in globals():
    resolve()
    sys.exit()

Solution (Python):
n, m = map(int,input().split())
li = list(map(int,input().split()))
sum = 0
for i in range(m):
  sum += li[i]

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

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

li_sum = sum(li)
res = n - li_sum
if res < 0:
    print('-1')
else:
    print(res)

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


if __name__ == "__main__":
    main()

Solution (Python):
MOD = 1000000007
ii = lambda :  int(input())
si = lambda :  input()
dgl = lambda : list(map(int, input()))
f = lambda :   map(int, input().split())
il = lambda :  list(map(int, input().split()))
ls = lambda :  list(input())
n,m=f()
a=il()
l=n-sum(a)
if(l>=0):
    print(l)
else:
    print(-1)

Solution (Python):



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

    n_day = sum(A)

    return N - n_day if N >= n_day else -1


print(main())

Solution (Python):


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

ans = 0
ans = N - sum(A)

if(ans <= -1):
    print('-1')
else:
    print(ans)

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


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

for i in range(n):
    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()))
print(max(-1, n-sum(a)))

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

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

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

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

total = sum(a)
ans = n - total

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

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

sum_A = sum(A)

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

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

Solution (Python):









import os
import sys

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

    print(n-sum(a))
    


if __name__ == "__main__":
    main()

Solution (Python):
x = input()
n = int(x.split()[0])
m = int(x.split()[1])
y = input()
list = y.split(' ')
sum = 0

for i in list:
    i = int(i)
    sum = sum + i

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

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

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

Solution (Python):
import sys; sys.setrecursionlimit(2147483647); input = sys.stdin.readline
from math import floor, ceil, sqrt, factorial, log
from collections import Counter, defaultdict, deque
from operator import itemgetter
INF = float('inf'); MOD = 10**9+7
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(MI())
def LIR(n): return [LI() for i in range(n)]
def IS(): return input().rstrip()

def main():
    N, M = MI()
    A = LI()
    s = sum(A)
    if s <= N:
        print(N-s)
    else:
        print(-1)
if __name__ == '__main__':
    main()

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

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

ans = n - sum(As)

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

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

Solution (Python):
num=list(map(int,input().split()))
num2=list(map(int,input().split()))
ans = num[0]

for i in range(num[1]):
    ans -= num2[i]

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

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

s=input().split()


k=0

for i in range(0,m):
    s[i]=int(s[i])
    k+=s[i]

ans=n-k

if ans<0:
    print(-1)

else:
    print(ans)

Solution (Python):
N,M=map(int, input().split())
A=list(map(int, input().split()))
 
sum = 0
for i in range(M):
  sum += A[i]
  if sum > N:
    break

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

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

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

s=sum(a)

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

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

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

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

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

ai = [int(i) for i in input().split()]

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

Solution (Python):
import sys
def input(): return sys.stdin.readline().rstrip()

def main():
  N, M = map(int, input().split())
  Asum = sum(map(int, input().split()))
  if (N - Asum) < 0:
    print('-1')
  else:
    print(N - Asum)

if __name__ == '__main__':
  main()

Solution (Python):


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

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

sum = 0

for i in range(M):
    sum += list1[i]

ans = N - sum

if ans < 0:
    ans = -1

print(ans)

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

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

vac = N - sum(la)

if vac >= 0:
    print(vac)

else:
    print(-1)

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

if sum(a) <= n:
  print(n - sum(a))
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 = input()
B = []
atemp = A.split()
c = 0
for i, num in enumerate(atemp):
    B.append(atemp[i])
    c += int(num)

if N-c < 0:
    print('-1')
else:
    print(N-c)

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 = list(map(int, input().split()))


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

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

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

Solution (Python):
n,m = map(int,input().split(' '))
data_ori = input().split(' ')
data = [int(data_ori[i]) for i in range(m)]
sum = 0
for i in range(m):
    sum += data[i]
if(n - sum < 0):
    print(-1)
else:
    print(n - sum)

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



for i in range(M):
    N = N - A[i]
    
if N < 0:
    print(-1)
else:
    print(N)

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

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

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

s = sum(a)

result = n - s

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

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

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

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

work = 0
for i in a:
    work+=i
if work > n:
    print("-1")
else:
    print(n - work)

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

ans = -1

if n - sum(a) > -1 :
  ans = n - sum(a)

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):
n,m = a,b = list(map(int,input().split()))
s = list(map(int,input().split()))

day = 0
for i in range(m):
    day += s[i]

ans = n - day

if ans < 0:
    ans = -1

print(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())
l = [int(x) for x in input().split()]
s = sum(l)
if s > m:
    print(-1) 
else:
    print(m-s)

Solution (Python):
from sys import stdin


def get_result(data):
    N, M = data[0]
    A = data[1]
    ans = N - sum(A)
    if ans < 0:
        return -1
    return ans


if __name__ == '__main__':
    raw_data = [val.rstrip() for val in stdin.readlines()]
    data = [list(map(int, val.split(' '))) for val in raw_data]
    result = get_result(data)
    print(result)

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

Solution (Python):
ip1 = input()
ip1list = ip1.split(" ")
N = int(ip1list[0])
M = int(ip1list[1])
ip2 = input()
A_sub = ip2.split(" ")
A = []
for a in A_sub:A.append(int(a))
r = N-sum(A)
if r < 0:
    print(-1)
else:
    print(r)

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

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

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

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

for i in list:
    sum += i

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

Solution (Python):
import sys


lines = 2
inp = list()

for _ in range(lines):
    inp.append(sys.stdin.readline().strip())


n = int(inp[0].split()[0])
a_lst = [int(i) for i in inp[1].split()]

rest = n - sum(a_lst)

rest = rest if rest >= 0 else -1

print(rest)

Solution (Python):

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

play_day = N-sum(A)

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

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

n = int(n)
m = int(m)

days = 0

for a in l_a:
  days += int(a)
  
if (n - days) < 0:
  print(-1)
else:
  print(n - days)

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

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

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

lis = map(int, input().split())
sum = sum(lis)

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

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

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

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

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

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

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

Solution (Python):
N, M = map(int, input().rstrip().split())
As = [int(x) for x in input().rstrip().split()]


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

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

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

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

Solution (Python):
data = [input().split() for i in range(2)]
NM = data[0]
N = int(NM[0])
M = int(NM[1])
A = data[1]
sum = 0
for i in A:
  sum += int(i)
result = N - sum
if result >=0:
  print(result)
else:
  print("-1")

Solution (Python):
line = input().split(" ")
summer_day = int(line[0])
summer_kadai = int(line[1])

kadai_list = input().split(" ")
hituyou_day = 0
for i in range(summer_kadai):
    hituyou_day = hituyou_day + int(kadai_list[i])

if (hituyou_day <= summer_day):
    print(summer_day - hituyou_day)
else:
    print("-1")

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

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

Solution (Python):
r, m = (int(each) for each in input().split())
a = [int(each) for each in input().split()]
print(max(r-sum(a), -1))