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






























































global FLAG_LOG
FLAG_LOG = False


def log(value):
    
    
    if FLAG_LOG:
        print(str(value))


def calculation(lines):
    
    
    N, M = list(map(int, lines[0].split()))
    values = list(map(int, lines[1].split()))
    
    
    
    
    
    
    

    result = max(N - sum(values), -1)

    return [result]



def get_input_lines(lines_count):
    lines = list()
    for _ in range(lines_count):
        lines.append(input())
    return lines



def get_testdata(pattern):
    if pattern == 1:
        lines_input = ['41 2', '5 6']
        lines_export = [30]
    if pattern == 2:
        lines_input = ['10 2', '5 6']
        lines_export = [-1]
    if pattern == 3:
        lines_input = ['11 2', '5 6']
        lines_export = [0]
    if pattern == 4:
        lines_input = ['314 15', '9 26 5 35 8 9 79 3 23 8 46 2 6 43 3']
        lines_export = [9]
    return lines_input, lines_export



def get_mode():
    import sys
    args = sys.argv
    global FLAG_LOG
    if len(args) == 1:
        mode = 0
        FLAG_LOG = False
    else:
        mode = int(args[1])
        FLAG_LOG = True
    return mode



def main():
    import time
    started = time.time()
    mode = get_mode()
    if mode == 0:
        lines_input = get_input_lines(2)
    else:
        lines_input, lines_export = get_testdata(mode)

    lines_result = calculation(lines_input)

    for line_result in lines_result:
        print(line_result)

    
    
    
    
    
    
    
    
    
    
    



if __name__ == '__main__':
    main()

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

print(n)

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

for h in a:
    n -= h
    if n < 0:
        print(-1)
        exit(0)

print(n)

Solution (Python):
import math
import sys
import collections
import bisect
readline = sys.stdin.readline


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


if __name__ == '__main__':
    main()

Solution (Python):


from typing import *
import itertools
import math
import sys

INF = float('inf')


def solve(N: int, M: int, A: "List[int]"):
    return max(N-sum(A), -1)


def main():

    sys.setrecursionlimit(10 ** 6)

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  
    M = int(next(tokens))  
    A = [int(next(tokens)) for _ in range(M)]  
    print(solve(N, M, A))


if __name__ == '__main__':
    main()

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

d = 0
for i in range(m):
  d += a[i]
  
ans = n-d
if ans < 0:
  print(-1)
else:
  print(ans)

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

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

for i in range(m):
  n -= lst[i]
  if n < 0:
    n = -1
    break

print(n)

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

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

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

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()))
print(max(-1, n - sum(a)))

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

if not ( 1 <= N <= 10 ** 6 and 1 <= M <= 10 ** 4 ): sys.exit()
if not ( 1 <= min(array) and max(array) <= 10 ** 4 ): sys.exit()

ans = N - sum(array)

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

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

total = sum(An)

if total > N:
    print('-1')
else:
    print(N - total)

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

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

Solution (Python):
def line(): return [int(i) for i in input().split(" ")]
n = line()[0]
for i in line(): n -= i
print(max(-1, n))

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

Solution (Python):
import sys
sys.setrecursionlimit(10**7) 
import math
from copy import copy, deepcopy
from copy import deepcopy as dcp
from operator import itemgetter
from bisect import bisect_left, bisect, bisect_right

from collections import deque, defaultdict


from collections import Counter

from itertools import accumulate,combinations,permutations,product

from heapq import heapify,heappop,heappush

from functools import reduce,lru_cache

from decimal import Decimal

def input(): 
    x=sys.stdin.readline()
    return x[:-1] if x[-1]=="\n" else x
def printe(*x):print("
def printl(li): _=print(*li, sep="\n") if li else None
def argsort(s, return_sorted=False): 
    inds=sorted(range(len(s)), key=lambda k: s[k])
    if return_sorted: return inds, [s[i] for i in inds]
    return inds
def alp2num(c,cap=False): return ord(c)-97 if not cap else ord(c)-65
def num2alp(i,cap=False): return chr(i+97) if not cap else chr(i+65)
def matmat(A,B):
    K,N,M=len(B),len(A),len(B[0])
    return [[sum([(A[i][k]*B[k][j]) for k in range(K)]) for j in range(M)] for i in range(N)]
def matvec(M,v):
    N,size=len(v),len(M)
    return [sum([M[i][j]*v[j] for j in range(N)]) for i in range(size)]
def T(M):
    n,m=len(M),len(M[0])
    return [[M[j][i] for j in range(n)] for i in range(m)]
def binr(x): return bin(x)[2:]
def bitcount(x): 
    x= x - ((x >> 1) & 0x5555555555555555)
    x= (x & 0x3333333333333333) + ((x >> 2) & 0x3333333333333333)
    x= (x + (x >> 4)) & 0x0f0f0f0f0f0f0f0f 
    x+= (x >> 8); x+= (x >> 16); x+= (x >> 32) 
    return x & 0x7f

def main():
    mod = 1000000007
    

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

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




if __name__ == "__main__":
    main()

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

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

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

Solution (Python):
N, M= map(int, input().split())
A = list(map(int, input().split()))
sum = 0
for i in range(len(A)):
    sum += A[i]
N = N - sum
if N >= 0:
    print(N)
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())
A = list(map(int, input().split()))
rest = N - sum(A)
if rest < 0:
  print(-1)
else:
  print(rest)

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

x  = N - sum(A)

if x < 0:
    x = -1

print(x)

Solution (Python):

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






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

main()

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())
l = sum(map(int,input().split()))
print(max(-1, n-l))

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

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

for i in a:
    b = b + i

if n >= b:
    print(n - b)
if n < b:
    print( -1 )

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

b = 0

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

if n >= b:
    print( n - b )

if n < b:
    print( -1 )

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

b = sum(a)

if n >= b:
    print( n - b )

if n < b:
    print( -1 )

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

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

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

Solution (Python):


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

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

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

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

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):
def main():
 n, m = map(int,input().split())
 a = list(map(int,input().split()))
 sum = 0
 for i in a:
  sum += i
 if sum <= n:
  print(n - sum)
 else:
  print(-1)
      
main()

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

ans = n - sum(a)

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

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

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

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

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

Solution (Python):
import sys
sys.setrecursionlimit(10**7)
input = sys.stdin.readline

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

if s <= n:
    print(n - s)
else:
    print(-1)

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

ans=n-sum(a_list)

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

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

playable_days = N - sum(A_list)

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

Solution (Python):
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    N, M, *A = map(int, read().split())

    ans = max(N - sum(A), -1)

    print(ans)

    return


if __name__ == '__main__':
    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().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()))

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

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()))
freeday = 0
needday = 0

for i in range(m):
    needday += a[i]
    if needday > n:
        freeday = -1
        break
else:
    freeday = n - needday

print(freeday)

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

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

Solution (Python):
n,m = map(int,input().split())
a = list(map(int,input().split()))
for v in a:
    n = n - v
    if n < 0:
        n = -1
        break
print(n)

Solution (Python):
N, M = (int(x) for x in 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(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 = sum(list(map(int, input().split())))

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

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

for i in A:
    N -= i

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

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

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

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

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

Solution (Python):
N,_ = map(int, input().split())
z = N - eval(input().replace(*' +'))
print(z if  0 <= z else -1 )

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

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

Solution (Python):
n, m = map(int, input().split())
sequence = list(map(int, input().split()))
a = sum(sequence)
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())
l=list(map(int,input().split()))
total=0
for k in range(M):
  total+=l[k]
if total<=N:
  print(N-total)
else:
  print("-1")

Solution (Python):
N,M=map(int,input().split())
A=list(map(int,input().split()))
count=0
for i in range(M):
    count+=A[i]
if count<=N:
    print(N-count)
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()]

a = sum(A)

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

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

res = n - sum(a)

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

Solution (Python):


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

l=list(map(int,input().split()))
x=0
for i in l:
    x += i
    
y=a-x
if y < 0:
    print(-1)
else:
    print(y)

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

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

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

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

Solution (Python):
n, m = (int(i) for i in input().split())
tot = sum(int(i) for i in input().split())

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

Solution (Python):
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


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

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

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:
    N = -1
    break
print(N)

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

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

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
input = sys.stdin.readline

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

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

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

sum_a = sum(a)
if n - sum_a <= -1:
  print('-1')
else:
  print(n - sum_a)

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

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

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

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

for i in range(Day[1]):
  Day[0] = Day[0] - work[i]
  
if(Day[0] >= 0):
  print(Day[0])
elif(Day[0] < 0):
  print("-1")

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

hw = sum(a)

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

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

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

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

if b > N :
    print(-1)
elif b <= N:
    print(N-b)

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

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

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

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

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

for i in a:
    s += int(i)

if int(s) <= int(n):
    print(int(n) - int(s))
else:
    print("-1")

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

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

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

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

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

Solution (Python):
(n, m) = map(int, input().split())
a = tuple(map(int, input().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()))
ans=n
for i in range(m):
    ans-=a[i]
if ans<0:
    ans=-1
print(ans)

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()))
a = sum(A)
if a<=N:
  print(N-a)
else:
  print(-1)

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

if n<sum(lst) : print(-1)
else : print(n-sum(lst))

Solution (Python):
import numpy as np

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

arr = np.array(lists)
days = arr.sum()

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

Solution (Python):

from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache
import sys
sys.setrecursionlimit(10000)
INF = float("inf")
YES, Yes, yes, NO, No, no = "YES", "Yes", "yes", "NO", "No", "no"
dy4, dx4 = [0, 1, 0, -1], [1, 0, -1, 0]
dy8, dx8 = [0, -1, 0, 1, 1, -1, -1, 1], [1, 0, -1, 0, 1, 1, -1, -1]


def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W


def ceil(a, b):
    return (a + b - 1) // b


def sum_of_arithmetic_progression(s, d, n):
    return n * (2 * s + (n - 1) * d) // 2


def gcd(a, b):
    if b == 0:
        return a
    return gcd(b, a % b)


def lcm(a, b):
    g = gcd(a, b)
    return a / g * b


def solve():
    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)


def main():
    solve()


if __name__ == '__main__':
    main()

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

a = list(map(int, input().split()))
sum = 0
for i in range(len(a)):
    sum += a[i]

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

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

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

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

print(N-A if N>=A else -1)

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

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

hwsum = 0

for n in range(len(hw)):
  hwsum += hw[n]

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

Solution (Python):

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

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

free_days = N - sum(A)

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

Solution (Python):

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

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

free_days = N - sum(A)

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

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()))
tmp = N - sum(A)

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

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

print(ans)

Solution (Python):
import sys
sys.setrecursionlimit(10 ** 9)

def int1(x): return int(x) - 1
def II(): return int(input())
def MI(): return map(int, input().split())
def MI1(): return map(int1, input().split())
def LI(): return list(map(int, input().split()))
def LI1(): return list(map(int1, input().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def MS(): return input().split()
def LS(): return list(input())
def LLS(rows_number): return [LS() for _ in range(rows_number)]
def printlist(lst, k=' '): print(k.join(list(map(str, lst))))
INF = float('inf')







def solve():
    N, M = MI()
    A = LI()

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

if __name__ == '__main__':
    solve()

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):
N, M  = map(int,input().split())
A = sum(map(int,input().split()))

if N >= A:
    print(N-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()))
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(-1)
else:
    print(n-sum(a))

Solution (Python):
from collections import defaultdict as dd
from collections import deque
import bisect
import heapq

def ri():
    return int(input())

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


def solve():
    n, m = rl()
    A = rl()
    print (max(n - sum(A), -1))






mode = 's'

if mode == 'T':
    t = ri()
    for i in range(t):
        solve()
else:
    solve()

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

ans=n

for i in range(m):
    ans-=a[i]
    if ans<0:
        ans=-1
        break
print(ans)

Solution (Python):
a, b = input().split()
s = list(map(int, input().split())) 
day = int(a) - sum(s) 
if day>=0:
  print(day)
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]

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

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

w = sum(A)
ans = N - w

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

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

if b<=n :
  print(n-b)
else:
  print(-1)

Solution (Python):
N , M = (int(a) for a in input().split())
A = list(map(int,input().split()))
d = sum(A)
print(max(N-d,-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())
shukudai = sum(list(map(int,input().split())))
  
if n >= shukudai:
  print(n-shukudai)
else:
  print(-1)

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

ans = max(N - sum(A), -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):
days, num = map(int, input().split())
hw = list(map(int, input().split()))
hang = days - sum(hw)
if hang < 0:
  print("-1")
else:
  print(hang)

Solution (Python):
import math
import sys

def dict_sort(ans):
    ans=sorted(ans.items(),reverse=True,key=lambda kv:(kv[1]))

def seive_primes(n):
    flag=[0]*(n+10)
    flag[1]=flag[0]=1
    i=2
    while i*i<=n+1:
        if flag[i]==0:
            j=i*i
            while j<=n+1:
                flag[j]=1
                j+=i
        i+=1
    return flag

def is_prime(n):
    if n==1:
        return 0
    for i in range(2,int(math.sqrt(n))+1):
        if n%i==0:
            return False
    return True

def gcd(a,b):
    if b==0:
        return a
    return gcd(b,a%b)

def lcm(a,b):
    return (a*b)//gcd(a,b)

def fact(n):
    if n==1:
        return n
    return fact(n-1)*n

def pow_2s(n):
    ls=[]
    for i in range(1,n+1):
        ls.append(2**i)
    return ls

def alphbates():
    return "abcdefghijklmnopqrstuvwxyz"

def inp():
    ls=list(map(int,input().split()))
    return ls

def mult_inp():
    return map(int,input().split())

n,m=mult_inp()
ls=inp()
print(max(n-sum(ls),-1))

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

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

ans = n - sum(li)

if ans < 0:
    ans = -1

print(ans)

Solution (Python):

n, m, *a = map(int, open(0).read().split())
d = n - sum(a)
if d <0:
    print(-1)
else:
    print(d)

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

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


def main():
    input = sys.stdin.buffer.readline
    n, m = map(int, input().split())
    a_list = list(map(int, input().split()))
    for a in a_list:
        n -= a
        if n < 0:
            break
    print(n if n >= 0 else -1)


if __name__ == '__main__':
    main()

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().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=list(map(int,input().split()))
sum=0
for i in range(M):
    sum+=A[i]

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

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

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=input().split()
 
s=0
for i in range(M):
  s+=int(A[i])
  
ans=N-s
if ans>=0:
  print(ans)
else:
  print("-1")

Solution (Python):
k=input()

list_a=k.split()

n=list_a[0]

m=list_a[1]

t=input()

list_b=t.split()

h=len(list_b)

list_s=[int(s) for s in list_b]

if int(m)==int(h) and sum(list_s) <= int(n):
  print(int(n)-sum(list_s))
elif int(m)==int(h) and sum(list_s) > int(n):
  print("-1")

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

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

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

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