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



Sample input:
41 2
5 6


Sample output:
30

Submission status: Accepted

Solution code:
from operator import add
import functools


n = input().split(" ")

list_homework = input().split(" ")
list_homework = [int(list_homework[i]) for i in range(len(list_homework))]  

rest_day = int(n[0]) - functools.reduce(add, list_homework)

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import numpy as np


if __name__ == '__main__':
    List = [list(map(int, input().split())) for i in range(2)]
    N=List[0][0]
    M=List[0][1]

    Time=np.array(List[1][:])
    sum_time= sum(Time)
    if(sum_time <= N):
        print(N-sum_time)
    else:
        print(-1)

Submission status: Accepted

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

goukei = sum(A_list)

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

Submission status: Accepted

Solution code:
import sys

def main():

	S = 0
	N,M = map(int, input().split())
	Lists = list(map(int, input().split()))
	
	count = 0
	
	for List in Lists:
		S += List
	if N-S >= 0 :
	
		print(N-S)
	
	else:
		print("-1")
	
if __name__ == "__main__":
    main()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
Ai_list = list(map(int, input().split()))

Ai_sum = sum(Ai_list)

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n, m = (int(i) for i in input().split())
a = list(int(i) for i in input().split())

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
a = list(map(int, input().split()))
sum = 0
for i in a:
    sum += i
if n >= sum:
    print(n - sum)
else:
    print(-1)

Submission status: Accepted

Solution code:
natsuyasumi,syukudai = input().split()
syukudailist = list(map(int,input().split()))
goukei = sum(syukudailist)
if goukei <= int(natsuyasumi):
	print(int(natsuyasumi)-goukei)
else:
	print(-1)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N,M = (input().strip().split())


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

x = int(N)
#残り日数
for j in range(int(M)):
    x = x - int(A[j])
    j += 1

if x < 0 :
    print(-1)

else :
    print(x)

Submission status: Accepted

Solution code:
print(max([-1,list(map(int,input().split()))[0]-sum(list(map(int,input().split())))]))

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
a=[int(x)for x in input().split()]
s=0
for i in range(m):s+=a[i]
print(max(-1,n-s))

Submission status: Accepted

Solution code:
m,n=[int(i) for i in input().split(' ')]
a_list=[int(i) for i in input().split(' ')]
play_m=m-sum(a_list)
print(play_m) if play_m>=0 else print(-1)

Submission status: Accepted

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

d = sum(c)

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

Submission status: Accepted

Solution code:
N,M = map(int,input().split())
list = [int(M) for M in input().split()]

a = N - sum(list)

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

Submission status: Accepted

Solution code:
n,k=map(int,input().split())
x=sum([int(n) for n in input().split()])
if n-x>=0:
  print(n-x)
else:
  print(-1)

Submission status: Accepted

Solution code:
n, m = [int(_) for _ in input().split()]
A = [int(_) for _ in input().split()]

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
days, counts = map(int, input().split())
li = list(map(int, input().split()))

for i in range(counts):
  days -= li[i]

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

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
day_cost = [int(i) for i in input().split()]
holidays = N-sum(day_cost)

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

Submission status: Accepted

Solution code:
n,m= map(int, input().split())
a = list(map(int, input().split()))
c = n-sum(a)
if m == len(a) and c>= 0:
    print(c)
else:
    print(-1)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import math
# 整数の入力
n, m = map(int, input().split())
li = list(map(int, input().split()))
# 計算
a = n-sum(li)
if 0 <= a:
    print(a)
else:
    print(-1)

Submission status: Accepted

Solution code:
N,M=map(int,input().split())
c=input().split()
if sum(int(i) for i in c)>N:
    print(-1)
else:
    print(N-sum(int(i) for i in c))

Submission status: Accepted

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

Submission status: Accepted

Solution code:

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

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

totalwork = sum(works)

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

Submission status: Accepted

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

s = sum(A)

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
A = input().split()
B = [ ]
for i in range(M):
  B.append(int(A[i]))
if(sum(B) == N):
  print('0')
elif(sum(B) < N):
  print(N - sum(B))
else:
  print('-1')

Submission status: Accepted

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

Submission status: Accepted

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

cnt = 0

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#B
N, K = map(int, input().split())
A = list(map(int, input().split()))
if sum(A)<=N:
    print(N-sum(A))
else:
    print(-1)

Submission status: Accepted

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

summer_vacation = a[0]
homework = a[1]
homework_for_days = sum(b)

if homework_for_days > summer_vacation:
    print(-1)
else:
    result = summer_vacation - homework_for_days
    print(result)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
a=list(map(int,input().split()))
b=list(map(int,input().split()))
N=a[0]
M=a[1]
sum_day = 0
for i in range(M):
    sum_day += b[i]
ans = N - sum_day
if ans < 0:
    print(-1)
else:
    print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def q2():
    N, M = (int(i) for i in input().split())
    A = [int(i) for i in input().split()]
    sum_A = sum(A)
    if N >= sum_A:
        ans = N - sum_A
    else:
        ans = -1
    print(ans)


if __name__ == '__main__':
    q2()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
a,b=map(int,input().split())
c=list(map(int,input().split()))
d=sum(c)
ans=a-d
if ans>=0:
    print(ans)
else:
    print('-1')

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N,M=map(int,input().split())
l1 = list(map(int, input().split()))

S=0
for i in range(0,M):
  S+=l1[i]
  
if N-S>=0:
  print(N-S)
else:
  print(-1)

Submission status: Accepted

Solution code:
import math

N, M = (int(x) for x in input().split())
A = list(map(int, input().strip().split()))


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

else:
    joy = N - sum(A)
    print(joy)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# -*- coding:utf-8 -*-

P = list(input().split())
N = int(P[0])
M = int(P[1])

A = list(input().split())
A = [int(i) for i in A]
SUM_A = sum(A)

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

Submission status: Accepted

Solution code:
LS = list(map(int,input().split()))
LT= list(map(int,input().split()))

S = LS[0]
T = sum(LT)

if S>=T:
  print(S-T)
else:
  print(-1)

Submission status: Accepted

Solution code:
sum=0
N=list(map(int,input().split()))
data=list(map(int,input().split()))
for i in range(N[1]):
    sum=sum+data[i]
if sum-1>N[0]:
    print(-1)
    exit()
else:
    print(N[0]-sum)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N,M =(input()).split()
x = (input()).split()
a = 0
k = []
b = 0
for i in (x):
    k.append(i)
for j in k:
    b = int(j) + b
v = int(N)-b
if v <0:
    n = -1
else:
    n = v
print (n)

Submission status: Accepted

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

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

Submission status: Accepted

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

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

Submission status: Accepted

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

a=[]
a=list(input().split())


for k in range(m):

    n=n-int(a[k])

    if n < 0:
        n=-1
        break

print(n)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
n, m, *aa = map(int, open(0).read().split())

st = 0
for i in range(1, m+1):
    st += aa[i-1]

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
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))  # type: int
    M = int(next(tokens))  # type: int
    A = [int(next(tokens)) for _ in range(M)]  # type: "List[int]"
    solve(N, M, A)

if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
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')

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
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')

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
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')

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
[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")

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
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')

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
#string = ' '.join(list(input() for _ in range(int(input()))))
n,m = map(int,input().split())
a = list(map(int,input().split()))
k = sum(a)
if k>n:
    print("-1")
else:
    print(n-k)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
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')

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

ans = N - sum(A)

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
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')

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

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

print(play)

Submission status: Accepted

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

Submission status: Accepted

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