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

Submission status: Accepted

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

Submission status: Accepted

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


for i in A:
  N -= i

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

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

sum = sum(A)

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

Submission status: Accepted

Solution code:

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

day = sum(A)
play = N-day
if play < 0:
    play = -1

print(play)

Submission status: Accepted

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

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

if n < 0:
	print("-1")
else:
	print("%d" % n)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
vacations, assignments = map(int, input().split())
days = sum(list(map(int,input().split())))

if days > vacations:
    print("-1")
else:
    print(vacations-days)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# 夏休みN日
# 宿題M
# i番目の宿題をやるにはAi日間かかります。

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

S = 0

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

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

Submission status: Accepted

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

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

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

Submission status: Accepted

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

Submission status: Accepted

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

sum = sum(lst)
print(n-sum if sum<=n else '-1')

Submission status: Accepted

Solution code:

from sys import stdin
import sys
# sys.setrecursionlimit(10**8)

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

import numpy as np

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

Submission status: Accepted

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

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

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

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

N = N - a_sum

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

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

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

sum_a = sum(list_b)

ans = N - sum_a

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

Submission status: Accepted

Solution code:
N,M=map(int,input().split())
A=list(map(int,input().split()))
i = 0
total = 0
while i<M:
    total += A[i]
    i+=1
if N<total:
    print("-1")
else:
    print(N-total)

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

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

days = 0

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

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
# abc136

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

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

Submission status: Accepted

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

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

std = sum(A)

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!
N,M = map(int,input().split())
A = list(map(int,input().split()))

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

Submission status: Accepted

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

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

s = 0

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

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

Submission status: Accepted

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

Submission status: Accepted

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

list = []

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

sum = 0

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

Submission status: Accepted

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

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

Submission status: Accepted

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

t = 0

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

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

Submission status: Accepted

Solution code:

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

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


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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

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

if __name__ == "__main__":
    main()

Submission status: Accepted

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

suma=sum(a)

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

Submission status: Accepted

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

    print(N)

solve()

Submission status: Accepted

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

Submission status: Accepted

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

sum_a = sum(A)

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

Submission status: Accepted

Solution code:

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
'''二分探索'''
#import bisect
'''デック'''
#from collections import deque
'''順列,組み合わせ,累積和,直積・forネスト'''
#from itertools import permutations, combinations, accumulate, product
'''小数点以下切り捨て,小数点以下切り上げ,平方根,階乗,最大公約数'''
#from math import floor, ceil, sqrt, factorial, gcd
'''input 文字列は最後に\nを含む'''
#import sys
#input = sys.stdin.readline


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

work_time = sum(a)

answer = N - work_time

if answer < 0:
    answer = -1


print(answer)

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

Submission status: Accepted

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

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

ans = sum(A)

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

else:
    print(N - ans)

Submission status: Accepted

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

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

for cost in a:
    n = n - cost

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
# スペース区切りの整数の入力
N, M = map(int, input().split())
# 文字列の入力
s = input()
t = s.split(" ")
sum = 0
for u in t:
    sum += int(u)
if sum > N:
    print(-1)
else:
    print(N-sum)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from heapq import heappush,heappop,heapify
from collections import deque,defaultdict,Counter
from itertools import permutations,combinations,groupby
import sys,bisect,string,math,time,functools,random
def Golf():*a,=map(int,open(0))
def I():return int(input())
def S_():return input()
def IS():return input().split()
def LS():return [i for i in input().split()]
def LI():return [int(i) for i in input().split()]
def LI_():return [int(i)-1 for i in input().split()]
def NI(n):return [int(input()) for i in range(n)]
def NI_(n):return [int(input())-1 for i in range(n)]
def StoLI():return [ord(i)-97 for i in input()]
def ItoS(n):return chr(n+97)
def LtoS(ls):return ''.join([chr(i+97) for i in ls])
def GI(V,E,Directed=False,index=0):
    org_inp=[];g=[[] for i in range(n)]
    for i in range(E):
        inp=LI();org_inp.append(inp)
        if index==0:inp[0]-=1;inp[1]-=1
        if len(inp)==2:
            a,b=inp;g[a].append(b)
            if not Directed:g[b].append(a)
        elif len(inp)==3:
            a,b,c=inp;aa=(inp[0],inp[2]);bb=(inp[1],inp[2]);g[a].append(bb)
            if not Directed:g[b].append(aa)
    return g,org_inp
def GGI(h,w,search=None,replacement_of_found='.',mp_def={'#':1,'.':0}):
#h,w,g,sg=GGI(h,w,search=['S','G'],replacement_of_found='.',mp_def={'#':1,'.':0}) # sample usage
    mp=[1]*(w+2);found={}
    for i in range(h):
        s=input()
        for char in search:
            if char in s:
                found[char]=((i+1)*(w+2)+s.index(char)+1)
                mp_def[char]=mp_def[replacement_of_found]
        mp+=[1]+[mp_def[j] for j in s]+[1]
    mp+=[1]*(w+2)
    return h+2,w+2,mp,found
def TI(n):return GI(n,n-1)
def bit_combination(k,n=2):
    rt=[]
    for tb in range(n**k):
        s=[tb//(n**bt)%n for bt in range(k)];rt+=[s]
    return rt
def show(*inp,end='\n'):
    if show_flg:print(*inp,end=end)

YN=['YES','NO'];Yn=['Yes','No']
mo=10**9+7
inf=float('inf')
l_alp=string.ascii_lowercase
#sys.setrecursionlimit(10**7)
input=lambda: sys.stdin.readline().rstrip()

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

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

show_flg=False
show_flg=True

ans=0

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

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

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

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

print(ans)

Submission status: Accepted

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

rem = N - sum(As)

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

Submission status: Accepted

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

value=sum(A)

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

else:
    print(-1)

Submission status: Accepted

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

ruikeitime = sum(a_lst)
# print(ruikeitime)
if n - ruikeitime < 0:
    print(-1)
else:
    print(n - ruikeitime)

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
from operator import itemgetter
import collections
import math

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


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

    
if __name__ == '__main__':
    main()

Submission status: Accepted

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

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

Submission status: Accepted

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

asum = sum(a)

ans = n-asum

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

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
# 2020/04/19
# AtCoder Beginner Contest 163 - B

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

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

ans = max(n - sum, -1)

# Output
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

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

main()

Submission status: Accepted

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

Submission status: Accepted

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

rem = n - sum(days)

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

Submission status: Accepted

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

print(ans)

Submission status: Accepted

Solution code:
# coding: utf-8

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

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

aa = sum(A)

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

Submission status: Accepted

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

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

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:
### ----------------
### ここから
### ----------------

import sys
from io import StringIO
import unittest

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

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

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

    n-=aaa
    if n<0:
        print(-1)
    else:
        print(n)
    #n=int(readline())
    #ss=readline().rstrip()
    #yn(1)

    return

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

### ----------------
### ここまで 
### ----------------

Submission status: Accepted

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

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

Submission status: Accepted

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

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

Submission status: Accepted

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


if __name__ == "__main__":
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# coding: utf-8


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

    n_day = sum(A)

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


print(main())

Submission status: Accepted

Solution code:
#!/usr/bin/env python

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

ans = 0
ans = N - sum(A)

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

Submission status: Accepted

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


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

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

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

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

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

Submission status: Accepted

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

total = sum(a)
ans = n - total

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

Submission status: Accepted

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

sum_A = sum(A)

if N < sum_A:
    print('-1')
else:
    print(N - sum_A)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# FileName: 	B
# CreatedDate:  2020-04-19 21:11:23 +0900
# LastModified: 2020-04-19 21:15:31 +0900
#


import os
import sys

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

    print(n-sum(a))
    


if __name__ == "__main__":
    main()

Submission status: Accepted

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

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

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

Submission status: Accepted

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

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

Submission status: Accepted

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

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

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

ans = n - sum(As)

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

Submission status: Accepted

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

Submission status: Accepted

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

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

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

Submission status: Accepted

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

s=input().split()


k=0

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

ans=n-k

if ans<0:
    print(-1)

else:
    print(ans)

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 sum > N:
    break

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

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

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

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

Submission status: Accepted

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

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

if __name__ == '__main__':
  main()

Submission status: Accepted

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

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

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

sum = 0

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

ans = N - sum

if ans < 0:
    ans = -1

print(ans)

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

Submission status: Accepted

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

vac = N - sum(la)

if vac >= 0:
    print(vac)

else:
    print(-1)

Submission status: Accepted

Solution code:
n, m = 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:
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:
N, M = map(int, input().split())
A = input()
B = []
atemp = A.split()
c = 0
for i, num in enumerate(atemp):
    B.append(atemp[i])
    c += int(num)

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

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


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

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