Problem:
 Score : 200 points    Problem Statement Takahashi has N days of summer vacation.  His teacher gave him M summer assignments. It will take A_i days for him to do the i -th assignment.  He cannot do multiple assignments on the same day, or hang out on a day he does an assignment.  What is the maximum number of days Takahashi can hang out during the vacation if he finishes all the assignments during this vacation?  If Takahashi cannot finish all the assignments during the vacation, print -1 instead.      Constraints  1 \leq N \leq 10^6  1 \leq M \leq 10^4  1 \leq A_i \leq 10^4         Input Input is given from Standard Input in the following format:  N  M  A_1  ...  A_M       Output Print the maximum number of days Takahashi can hang out during the vacation, or -1 .        Sample Input 1 41 2
5 6      Sample Output 1 30  For example, he can do the first assignment on the first 5 days, hang out on the next 30 days, and do the second assignment on the last 6 days of the vacation. In this way, he can safely spend 30 days hanging out.       Sample Input 2 10 2
5 6      Sample Output 2 -1  He cannot finish his assignments.       Sample Input 3 11 2
5 6      Sample Output 3 0  He can finish his assignments, but he will have no time to hang out.       Sample Input 4 314 15
9 26 5 35 8 9 79 3 23 8 46 2 6 43 3      Sample Output 4 9

Solution (Python):

import sys


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

    print(N-sum(A))
    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 = (int(x) for x in input().split(" "))
List= [int(y) for y in input().split(" ")]

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

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

Solution (Python):
import numpy as np
N, M = [int(a) for a in input().split()]
A = [int(a) for a in input().split()]

if np.sum(A) > N:
    print(-1)
    exit()

print(N - np.sum(A))

Solution (Python):
import numpy as np

N = int(input().split()[0])
A = np.array(list(map(int, input().split())))
Needed = np.sum(A)
if Needed > N:
    print(-1)
else:
    print(N - Needed)

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

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

Solution (Python):
days, taskNum = map(int, input().split(" "))

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

result = days - sum(taskSizes)

result = result if result >= 0 else -1

print(result)

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

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

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

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

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

hw = 0
for i in range(M):
    hw += int(As[i])

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

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

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

res = 0
for i in A:
    res += i

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

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

t = sum(a_list)


if int(N) < t:
    print('-1')
else:
    print(int(N) - t)

Solution (Python):
import numpy as np
N, M = map(int,input().split())
A = map(int, input().split())
A = list(A)
A = np.sum(A)
ans = N-A
if ans<0:
    ans=-1
print(ans)

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

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

w = sum(A)

r = N-w

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

Solution (Python):
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
import numpy as np

def main():
    N, M, *A = map(int, read().split())
    ans = sum(A)
    if ans > N:
        ans = -1
    else:
        ans = N - ans
    print(ans)
    return

if __name__ == '__main__':
    main()

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

Solution (Python):
n, m = map(int, input().split())
a = map(int,input().split())
t=0
for x in a:
    t += x
if n < t:
    print("-1")
else:
    print(n-t)

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

while L < N:
    M = M - A[L]
    L += 1

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

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

Solution (Python):
n,m=map(int, input().split())
s = input().rstrip().split(' ')
lst = []
for i in range(m):
  lst.append(int(s[i]))
n = n-sum(lst)
if n >=0:
  print(n)
elif n < 0:
  print(-1)

Solution (Python):
day, homework = map(int, input().split())
homeworkday = list(map(int, input().split()))

for num in range(len(homeworkday)):
  day -= homeworkday[num]

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

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

jj = sum(j)

if i[0]-jj < 0:
    print(-1)
else:
    print(i[0]-jj)

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

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

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

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

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

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

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):
from sys import stdin
N,M = stdin.readline().rstrip().split()
a_list = stdin.readline().rstrip().split()
N,M = int(N),int(M)
for a in a_list:
  N-=int(a)
if(N>=0):
  print(N)
else:
	print('-1')

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

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

ans = N - sum(L)

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

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

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

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

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

Solution (Python):
day, hw1 =  (int(x) for x in input().split())
hw2 = list(int(x) for x in input().split())
for i in range(hw1):
  day = day - hw2[i]
if day >= 0:
  print(day)
else:
  print(-1)

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

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())
list = list(map(int, input().split()))
 
m=0
for i in range (0, len(list)):
	m=m+list[i]
if N-m>=0:
	print(N-m)
elif N-m<0:
	print(-1)

Solution (Python):
import sys
lines = sys.stdin.read().splitlines()
description = lines[0].split()
summer_holiday_total = int(description[0])
time_required_for_hw = lines[1].split()
total = 0
for v in time_required_for_hw:
    total += int(v)

if summer_holiday_total - total < 0:
    print("-1")
else:
    print(summer_holiday_total - total)

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

T = 0
for i in range(M) :
    T += A[i-1]

F = N - T

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

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

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

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

Solution (Python):
s = [input() for i in range(2)] 
li1 = list(map(int, s[0].split()))
li2 = list(map(int, s[1].split()))
k=0;
for j in li2:
    k+=j
if li1[0] > k or li1[0] == k:
    print(li1[0]-k)
else:
    print('-1')

Solution (Python):
import numpy as np

length,hm = map(int,input().split())

time = list(map(int,input().split()))
ans = length - np.sum(time)

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

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

Solution (Python):
date0=input().rstrip().split(" ")
day=int(date0[0])
num=int(date0[1])
date1=input().rstrip().split(" ")
sum=0
for i in range(num):
  sum+=int(date1[i])
if day-sum>=0:
  print(day-sum)
else:
  print(-1)

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

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

sum=0
for i in range(len(l)):
    sum=sum+l[i]
    
if(sum>n):
    print("-1")
    
else:
    print(n-sum)

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

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

Solution (Python):

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

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

x = sum(a)

s = n - x

ans = max(s, -1)
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):
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())
s = 0
a = list(map(int,input().split()))
for i in a:
    s += i

t = n-s

if t >=0:
    print(t)

else:
    print('-1')

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

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

ans = N - sum(A)

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

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

for i in A:
    sumA = sumA + A[cnt]
    cnt = cnt +1

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

Solution (Python):
import numpy as np
n, m = map(int, input().split())
array = list(map(int, input().strip().split()))

a=sum(array)

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

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

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

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

for i in range(M):
    A_sum += A[i]

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

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 = 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):
a=input()
b=input()

aa=a.split(' ')
N=int(aa[0])
M=int(aa[1])

bb=b.split(' ')
sum=0
for b1 in bb:
    sum+=int(b1)

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

Solution (Python):
x =(input()).split(" ")
N = int(x[0])
y = (input()).split(" ")
yi = [int(s) for s in y]
for i in yi:
	N-=i
if N >=0:
	print(N)
else:
	print(-1)

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

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

Solution (Python):
N,M = input().split()
day = input().split()
days = []
for d in day:
    days.append(int(d))

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

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


if __name__ == "__main__":
    main()

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

x = sum(map(int,input().strip().split()))

print(n -x if x <= n else -1)

Solution (Python):
from sys import stdin


def main():
    M, N = map(int, stdin.readline().rstrip().split(" "))
    xs   = list(map(int, stdin.readline().rstrip().split(" ")))
    d    = M - sum(xs)
    
    if d >= 0:
       print(d)
    else:
       print(-1)
        
if __name__ == "__main__":
  main()

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

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

a = 0
b = 0

for i in M:
    a += int(i)
b = N-a
if b >= 0:
    print(b)
else:
    print(-1)

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

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

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

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

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

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

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

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

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

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

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

print(play)

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

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

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

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

Solution (Python):


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

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

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

print("{}".format(ans))

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


result = n - sum(a)

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

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

A =[]

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

gokei = int(sum(A))

if N - gokei < 0:
  print('-1')

else:
  print(N - gokei)

Solution (Python):
import numpy as np

NM=np.array(input().split(),dtype=np.int32)
N=NM[0]
M=NM[1]

A=np.array(input().split(),dtype=np.int32)

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

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

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

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

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

Solution (Python):










N, M = map(int, input().split())
array = list(map(int, input().strip().split()))
for value in array :
  N -= value
if N < 0 :
  N = -1
print(N)

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

Solution (Python):
def main():
  n,m = map(int, input().split())
  A = [int(x) for x in input().split()]
  for a in A:
      n = n - a
  if n >= 0:
      print(n)
  else:
      print('-1')
  
if __name__ == "__main__":
    main()
    pass

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

count = N
for i in A_list:
    N -= int(i)
if N >= 0:
    print(N)
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(n)
if n < 0:
    print(-1)

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

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()))
sum = 0
for i in a:
  sum += int(i)
p = n - sum
if p >= 0:
  print(p)
else:
  print('-1')

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

Work = input().split()

Worksum = 0
for n in Work:
  Worksum += int(n)
 
if int(N)-Worksum < 0:
  print(-1)
else:
  print(int(N)-Worksum)

Solution (Python):
total_day , h_w = input().split()

data = list(map(int,input().split()))
work_day = sum(data)
free = int(total_day) - work_day

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

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

Solution (Python):
N, M = map(int, input().split())
num= map(int, input().split())
sum1=sum(num)
if sum1>N:
    print("-1")
elif sum1<N:
    C=N-sum1
    print(C)
elif sum1==N:
    print("0")

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

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

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

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

s = sum(l)

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

Solution (Python):
import numpy as np

N, M = map(int, input().split())
H_list = [int(x) for x in input().split()]
np_H_list = np.array(H_list)
H_days = np.sum(np_H_list)

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

else:
    print(-1)

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

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

Solution (Python):

import sys
import math
from bisect import bisect_left
from bisect import bisect_right
import collections
import copy
import heapq
from collections import defaultdict
from heapq import heappop, heappush
import itertools
input = sys.stdin.readline
from collections import defaultdict
from heapq import heappop, heappush

from decimal import *

























def inputInt(): return int(input())
def inputMap(): return map(int, input().split())
def inputList(): return list(map(int, input().split()))

inf = float('inf')
mod = 1000000007




def main():
	N,M = inputMap()
	A = inputList()

	totals = 0
	for i in A:
		totals += i

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

	





def combination(n, r, mod=10**9+7):
    r = min(r, n-r)
    res = 1
    for i in range(r):
        res = res * (n - i) * modinv(i+1, mod) % mod
    return res


def modinv(a, mod=10**9+7):
    return pow(a, mod-2, mod)

def egcd(a, b):
    if a == 0:
        return b, 0, 1
    else:
        g, y, x = egcd(b % a, a)
        return g, x - (b // a) * y, y



def H(n, r, mod=10**9+7):
	
	
    return combination(n+r-1, r, mod)

class Combination:
    """
    O(n)の前計算を1回行うことで，O(1)でnCr mod mを求められる
    n_max = 10**6のとき前処理は約950ms (PyPyなら約340ms, 10**7で約1800ms)
    使用例：
    comb = Combination(1000000)
    print(comb(5, 3))  
    """
    def __init__(self, n_max, mod=10**9+7):
        self.mod = mod
        self.modinv = self.make_modinv_list(n_max)
        self.fac, self.facinv = self.make_factorial_list(n_max)

    def __call__(self, n, r):
        return self.fac[n] * self.facinv[r] % self.mod * self.facinv[n-r] % self.mod

    def make_factorial_list(self, n):
        
        
        fac = [1]
        facinv = [1]
        for i in range(1, n+1):
            fac.append(fac[i-1] * i % self.mod)
            facinv.append(facinv[i-1] * self.modinv[i] % self.mod)
        return fac, facinv

    def make_modinv_list(self, n):
        
        modinv = [0] * (n+1)
        modinv[1] = 1
        for i in range(2, n+1):
            modinv[i] = self.mod - self.mod//i * modinv[self.mod%i] % self.mod
        return modinv

if __name__ == "__main__":
	main()

Solution (Python):
N, M, *A = map(int, open(0).read().split())
print(max(N - sum(A), -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):
import sys
readline = sys.stdin.buffer.readline
n,m= list(map(int,readline().rstrip().split()))
arr = list(map(int,readline().rstrip().split()))
cnt =0
for i in range(m):
  cnt += arr[i]

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

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

Solution (Python):
A, B = map(int, input().split())
l = list(map(int, input().split()))
count = 0
for a in l:
    count += a
output = A - count
if output < 0:
    print(-1)
else:
    print(output)

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

ns_time = sum(a_list)

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

Solution (Python):
mn = input().split()
mn = [int(x) for x in mn]
n = mn[0]
m = mn[1]
a = input().split()
a  = [int(x) for x in a]


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

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

Solution (Python):
import sys
from pprint import pprint

N, M = map(int, sys.stdin.readline().strip().split())
A = list(map(int, sys.stdin.readline().strip().split()))

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

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

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

Solution (Python):
import numpy as np

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

suma=np.sum(A)
remain=N-suma

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

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

Solution (Python):
R = lambda: map(int, input().split())
n, m = R()
print(max(n - sum(R()), -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()))

SumA = sum(A)

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

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

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

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

Solution (Python):
import sys
import math
from collections import deque
MAX_INT = int(10e10)
MIN_INT = -MAX_INT
mod = 1000000007
sys.setrecursionlimit(1000000)
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

N,M = IL()
a = IL()

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

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

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

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

Solution (Python):
vacationDayCount, homeworkCount = map(int, input().split())
requiredDayList = list(map(int, input().split()))

playableDayCount = vacationDayCount - sum(requiredDayList)

if(playableDayCount >= 0):
    print(playableDayCount)
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 = map(int, input().split())
a = list(map(int, input().split()))
work = 0

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

if n >= work:
    print(n - work)
else:
    print("-1")

Solution (Python):
in1 = input().split(" ")
A = input().split(" ")
sum = 0
for a in A:
    sum += int(a)
ans = int(in1[0]) - sum
if ans >= 0:
    print(ans)
else:
    print(-1)

Solution (Python):
N,M = (int(x) for x in input().split())
array = list(map(int, input().strip().split()))
if(N>=sum(array)):
    print(N-sum(array))
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 = input().split()
m = input().split()
n = [int(i) for i in n]
m = [int(i) for i in m]
a = n[0]
for i in m:
  a -= i
  
if a<0:
  print("-1")
else:
  print(a)

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

Solution (Python):
import sys
sys.setrecursionlimit(300000)

def I(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LMI(): return list(map(int, sys.stdin.readline().split()))
MOD = 10 ** 9 + 7
INF = float('inf')


N, M = MI()
A = LMI()

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

Solution (Python):
nm = input()
ai = input()

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

total = 0

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

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

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

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

Solution (Python):
l = [list(map(int, input().split())) for i in range(2)]
if l[0][0] < sum(l[1]):
  print(-1)
else:
  print(l[0][0] - sum(l[1]))

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

if __name__ == "__main__":
    main()

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

Solution (Python):
input_1 = input()
input_2 = input()
term, work_cnt = input_1.split(' ')
works = input_2.split(' ')

play_days = int(term)
for i in range(int(work_cnt)):
  play_days -= int(works[i])

if play_days < 0:
  play_days = -1

print(play_days)

Solution (Python):
from math import pi

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

    total = sum(A)
    result = N - total

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

if __name__ == '__main__':
    main()

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
import socket

hostname = socket.gethostname()

if hostname == 'F451C':
    sys.stdin = open('b1.in')


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


def read_str_list():
    return input().split()


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


def read_str():
    return input()


def main():
    N, M = read_int_list()
    A = read_int_list()
    for i in range(M):
      total = sum(A)
    res = N - total
    if res < 0:
      res = -1
    print(res)


main()

Solution (Python):
days,works = input().strip().split()
days,works = [int(days),int(works)]

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

sum = 0
for i in range(works):
    sum += array[i]
days -= sum
if days >= 0:
    print(days)
else:
    print("-1")