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):
def calc(n, l):
    p = sum(l)
    if p > n:
        return -1
    else:
        return n - p
n, m = map(int,input().split())
l = [int(x) for x in input().split()]
print(calc(n, l))

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

Solution (Python):
n,_,*a=map(int,open(0).read().split())
print(max(-1,n-sum(a)))

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

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

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

sum = sum(list)

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

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

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

Solution (Python):



import sys
readline = sys.stdin.readline
read = sys.stdin.read

n,m,*a = [int(i) for i in read().split()]
print(max(-1,n-sum(a)))

Solution (Python):
o=input().rstrip().split(' ')
p=input().rstrip().split(' ')
S=0;
for i in range(0,len(p)):
    S+=int(p[i])
if S>int(o[0]):
    print(-1)
else:
    print(int(o[0])-S)

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

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

res = 0
for i in range(M):
    res += P[i]

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

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

Solution (Python):
tmp = input().split(" ")
N = int(tmp[0])
M = int(tmp[1])
tmp = input().split(" ")
A = [int(i) for i in tmp]
N -= sum(A)
if N<0:
  N = -1
print(N)

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


if __name__ == "__main__":
    main()

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

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

sum_A_i = sum(A_i)

result = N - sum_A_i

if result < 0:
    result = -1

print(result)

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

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

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

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

Solution (Python):
if __name__ == "__main__":
    n, m = map(int, input().split())
    al = list(map(int, input().split()))
    res = sum(al[:m])
    res = n - res
    if res < 0:
        print("-1")
    else:
        print(res)

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

Solution (Python):
import numpy as np
N,M = map(int,input().split())
homeworks = np.asarray(list(map(int,input().split())))
homeworks = np.sum(homeworks)
print(N-homeworks) if N >= homeworks else print('-1')

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

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

Solution (Python):
import numpy as np
n, m = map(int,input().split())
a = np.array(input().split(),dtype=int)
sum = 0

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

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

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

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

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

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

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

leftday = int(NM[0])
for Ai in(A):
    leftday = leftday - int(Ai)

if leftday >= 0:
    print(leftday)

elif leftday < 0:
    print("-1")

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

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

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

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

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

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

Solution (Python):
a=[] 
while True:
    try:
        a.append(list(map(int,input().split())))

    except:
        break;
        

b=a[0][1]
cnt = 0
kadai = []
s=0

while  cnt != b:
    kadai.append(a[1][cnt])
    cnt = cnt + 1

for i in kadai:
    s = s + i
    
if a[0][0]-s>=0:
    print(a[0][0]-s)
else:
    print('-1')

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

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

print (play)

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

Solution (Python):
def main():
    m, n = map(int, input().split())
    Sum = 0
    A = list(map(int, input().split()))
    for i in range(n):
        Sum+=A[i]
    if Sum>m:
        print(-1)
    else:
        print(m-Sum)
 
if __name__=='__main__':
    main()

Solution (Python):
import numpy as np

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

a = sum(r)
p = N - a 
if p < 0:
    p = -1

print(p)

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

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

a = sum(l)

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

else:
    print(-1)

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

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

Solution (Python):
import math



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





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

sum = 0
for syukudai in list:
    sum += syukudai

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

Solution (Python):
a = input().rstrip().split(" ")
n = int(a[0])
m = int(a[1])
b = input().rstrip().split(" ")

k=0
s=0

for i in range(m):
    s += int(b[k])
    k += 1

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

Solution (Python):
n, m = map(int, input().split())
suma = 0
a = []
a.append(input().split())

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

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

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

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

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

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

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

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)


if __name__ == "__main__":
    main()

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

Solution (Python):
line = input().rstrip().split(' ')
n = int(line[0])
m = int(line[1])

line = input().rstrip().split(' ')
for i in range(m):
    a = int(line[i])
    n -= a

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

Solution (Python):
x,y=input().split()
x=int(x)
y=int(y)
sum=0
for i  in input().split():
	sum+=int(i)

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

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

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

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

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

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

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

Solution (Python):
nm = input().split(' ')

N, M = int(nm[0]), int(nm[1])

A = input().split()

A_sum = 0

for i in A:
    A_sum += int(i)

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

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

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

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

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

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

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

if F<0: 
    print(-1)

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

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

a = sum(A)
ans = N-a
if ans >= 0:
    print(ans)
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()))
a.sort()
if sum(a) > n:
    print(-1)
else:
    print(n - sum(a[::2]) - sum(a[1::2]))

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

Solution (Python):
NM = input()
day, num = NM.split(' ')
day, num = int(day), int(num)
assignments = input().split(' ')

for i in range(num):
    day -= int(assignments[i])

if day >= 0:    
    print(day)
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())
homework = list(map(int, input().split()))
s = sum(homework)
if n - s >=0:
  print(n-s)
else:
  print(-1)

Solution (Python):

import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub


input = sys.stdin.buffer.readline
INF = 2**62-1

def read_int():
    return int(input())


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


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input().strip()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


@mt
def slv(N, M, A):

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


def main():
    N, M = read_int_n()
    A = read_int_n()
    print(slv(N, M, A))


if __name__ == '__main__':
    main()

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

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

Solution (Python):
days, assignment = [int(x) for x in input().split()]
assign = [int(x) for x in input().split()]
as_sum = sum(assign)
if as_sum > days:
    print(-1)
else:
    print(days - as_sum)

Solution (Python):
n,m=map(int,input().split())
*a,=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 sum(a)>n:
    print('-1')
else:
    print(n-sum(a))

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

if N-goukei<0:
    r=-1
else:r = N-goukei
print(r)

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






from sys import stdin,setrecursionlimit










setrecursionlimit(10**6+1)
input=stdin.readline

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





from sys import stdin

import time
import numpy as np




temp = stdin.readline().split()
N = int(temp[0])
M = int(temp[1])

data = []
write = stdin.readline().split()
for i in range(M):
    data.append(int(write[i]))

data = np.asarray(data)
data = np.sum(data)

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

Solution (Python):
import numpy as np
N, M = map(int, input().split()) 
A = np.array(list(map(int, input().split())))
hwdays = A.sum()
if N >= hwdays:
    print(int(N-hwdays))
else:
    print(-1)

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

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

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

total = sum(a)

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

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

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

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

if __name__ == "__main__":
    main()

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 = input().strip().split()
n,m = [int(n), int(m)]
array = list(map(int, input().strip().split()))
sumday = sum(array)
if n < sumday:
  print(-1)
else:
  print(n - sumday)

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

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

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

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

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

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

day = n

for b in a:
    day = day - b

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

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

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

a=0

for i in range(0,m):
    a+=A[i]
    
if a>n:
    print("-1")
else:
    print (n-a)

Solution (Python):
N,M = map(int, input().split())
A = input().split()
asum = 0
for i in A:
  asum += int(i)

print(max(N-asum, -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_n = list(map(int ,input().split()))

A_n.reverse()
ans=N
for i in range(M):
    ans -= A_n[i]
    
if ans>=0:
    print(ans)
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):
s = [input() for i in range(2)]
l1=s[0].split(" ")
l2=s[1].split(" ")

d=int(l1[0])
h_c=0
for h in l2:
  h_c+=int(h)
  
if h_c > d:
  print(-1)
else:
  print(d-h_c)

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

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

Solution (Python):


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

sumday = 0
for j in  range(M):
  sumday = sumday + day[j]

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

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

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

Solution (Python):
"""
NTC here
"""
 


import os
import sys
from io import BytesIO, IOBase

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

def main():
    T = 1
    while T:
        T-=1
        n, m = lin()
        a = lin()
        sm = sum(a)
        print(max(-1, n-sm))

        
        










BUFSIZE = 8192


class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)


class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")


sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")



if __name__ == "__main__":
    main()

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

Solution (Python):
N,M=map(int,input().split())
TaskList=list(map(int,input().split()))
    
res=0
for i in TaskList:
    res+=int(i)

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

else:
    print(-1)

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

Sum = 0

for B in A: 
	Sum=Sum+B

if N<Sum: 
	Re=-1
else:
	Re = N - Sum
    
print(Re)

Solution (Python):
val = list(map(int, input().split(" ")))
data = list(map(int, input().split(" ")))

if sum(data) > val[0]:
    print(-1)
else:
    print(val[0] - sum(data))

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):
import math
def main():
    N, M = map(int, input().split())
    l = [int(_) for _ in input().split()]
    summer_vacation_day_count = sum(l)
    if summer_vacation_day_count <= N:
        out = N - summer_vacation_day_count
    else:
        out = -1
    print(out)
main()

Solution (Python):
n,m=map(int,input().split())
a=[int(x) for x in 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()))
A = sum(A)
ans = n-A
if ans<0:
  ans = -1

print(ans)

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

a = sum(AS)

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

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

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

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

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

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

Solution (Python):
s = list(map(int, input().strip().split(' ')))
A = list(map(int, input().strip().split(' ')))
N = s[0]
M = s[1]
deadline = 0

for i in range(M):
    deadline = deadline + A[i]
    
if deadline > N:
    print('-1')
else:
    ans = N - deadline
    print(ans)

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

sum=0
for i in range(len(task)):
  sum=sum+task[i]

if N[0] < sum:
  print(-1)
else:
  print(N[0]-sum)

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()))
s=0
for i in range(m):
	s+=a[i]
if(n<s):
	print(-1)
else:
	val=n-s
	print(val)

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

def solve(N, M, A):
    x = N - sum(A)
    return x if x >= 0 else -1
    

if __name__ == '__main__':
    inputs = read()
    print("{}".format(solve(*inputs)))

Solution (Python):
days, num = input().split()
works = input().split()

days = int(days)
for i in works:
  days -= int(i)
if days < 0:
  print('-1')
else:
  print(days)

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

Solution (Python):

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

S = sum(arr)
N = int(n)

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

else:
  	print(N-S)

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

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

for m in range(M):
    sum = sum + A[m]

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

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

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

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

Solution (Python):

import sys



def solve(N: int, M: int, A: "List[int]"):
    print(N-sum(A) if N>=sum(A) else -1)
    return



def main():
    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)]  
    solve(N, M, A)

if __name__ == '__main__':
    main()

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

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

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

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

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

need_day = sum(A)

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

Solution (Python):
all_days, hw_num = map(int, input().split())
work = 0

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

for hw_day in hw_days:
    work += hw_day

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

Solution (Python):
N,M=input().split()
N=int(N)
M=int(M)
A=[int(x) for x in input().split()]
i=0
sum_A=0
result=0
if (1<=N<=10**6)and(1<=M<=10**4):
    for i in range(0,M):
        if 1<=A[i]<=10**4:
            sum_A+=A[i]
            i+=1
    result=N-sum_A
    if result<0:
        print(-1)
    else:
        print(result)

Solution (Python):
input_line=input().split()
days=int(input_line[0])
home_kinds=int(input_line[1])
required_days=input().split()
total_homework=0

for i in range(home_kinds):
    total_homework=total_homework+int(required_days[i])

if days >=total_homework:
    print(days-total_homework)
else:
    print(-1)

Solution (Python):
value = input().split(' ')
vacation = int(value[0])
homework = int(value[1])
daysInt = []

daysStr = input().split(' ')
for i in range(0, homework):
    daysInt.append(int(daysStr[i]))

sumDays = sum(daysInt)

if sumDays > vacation:
    print('-1')
else:
    print(vacation-sumDays)

Solution (Python):
i = list(map(int, input().split()))
j = list(map(int, input().split()))
a = 0
for cc in j:
  if 1 <= cc and cc <= 10**4:
    a += 1
    
if i[1] == a:
  if 1 <= i[0] and i[0] <= 10**6 and 1 <= i[1] and i[1] <= 10**4:
    if i[0] >= sum(j):
      print(i[0] - sum(j))
    else:
      print('-1')

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

task_days = sum(A)

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

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

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

    
playday = N - sum(A)

if playday <0:
    playday = -1
    

print(playday)

Solution (Python):


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

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