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:
duration, homeworks_count = [int(x) for x in input().split(' ')]
homework_lengths = [int(x) for x in input().split(' ')]

print(max(duration - sum(homework_lengths), -1))

Submission status: Accepted

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

suma = sum(listA)
out = n - suma
if out >= 0:
  print(out)
else:
  print("-1")

Submission status: Accepted

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

tot = sum(a)
ans = max(-1, n-sum(a))
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)>=0 else -1)

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N, K = [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:
a,b = map(int,input().split())
c = list(map(int,input().split()))

if(sum(c)-a >0):
    print("-1")
else:
    print(a-sum(c))

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
N,M = map(int,input().split())
A = list(map(int,input().split()))
x = sum(A)
if N >= x:
  print(N-x)
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:
n,m=map(int,input().split())
a=list(map(int,input().split()))
total=sum(a)
print("-1" if n<total else n-total)

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,=map(int,input().split())
for a in A: N-=a
print(-1 if N < 0 else N)

Submission status: Accepted

Solution code:
import sys
from random import choice,randint
inp=sys.stdin.readline
out=sys.stdout.write
flsh=sys.stdout.flush
 
sys.setrecursionlimit(10**9)
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]
 
def MI(): return map(int, inp().strip().split())
def LI(): return list(map(int, inp().strip().split()))
def LLI(): return [list(map(int, l.split())) for l in sys.stdin.readlines().strip()]
def LI_(): return [int(x)-1 for x in inp().strip().split()]
def LF(): return [float(x) for x in inp().strip().split()]
def LS(): return inp().strip().split()
def I(): return int(inp().strip())
def F(): return float(inp().strip())
def S(): return inp().strip()
def pf(s): return out(s+'\n')
def JA(a, sep): return sep.join(map(str, a))
def JAA(a, s, t): return s.join(t.join(map(str, b)) for b in a)

def main():
    n,m=MI()
    a = LI()
    s = sum(a)
    if s>n:
        print(-1)
    else:
        print(n-s)

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
A,B=map(int,input().split())
Lis=list(map(int,input().split()))

if A>=sum(Lis):
    print(A-sum(Lis))

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

Submission status: Accepted

Solution code:
import sys


try:
    sys.stdin = open(sys.path[0] + '\\input.txt', 'r')
    sys.stdout = open(sys.path[0] + '\\output.txt', 'w')
except FileNotFoundError:
    pass


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

sm = n - sum(arr)

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
t=list(map(int,input().split()))		
s=list(map(int,input().split()))		
 
temp = 0
for i in s:
  temp += i

# print(temp)
if(t[0]-temp>=0):
  print(t[0]-temp)
else:
  print(-1)

Submission status: Accepted

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

Submission status: Accepted

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

ans = N - sum(A)

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

result = 0

for i in A:
    result = result + i

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

Submission status: Accepted

Solution code:
def input_int_list():
    return [int(thing) for thing in input().split(" ")]

def int_input():
    return int(input())

N,M=input_int_list()
A_list=input_int_list()

ans=N-sum(A_list)
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
for i in range(m):
    day=day-a[i]
if day<0:
    print("-1")
else:
    print(day)

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]

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
from bisect import bisect_left, bisect_right
import sys, random, itertools, math
sys.setrecursionlimit(10**5)
input = sys.stdin.readline
sqrt = math.sqrt
def LI(): return list(map(int, input().split()))
def LF(): return list(map(float, input().split()))
def LI_(): return list(map(lambda x: int(x)-1, input().split()))
def II(): return int(input())
def IF(): return float(input())
def S(): return input().rstrip()
def LS(): return S().split()
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = float("INF")

#solve
def solve():
    n, m = LI()
    a = LI()
    a = sum(a)
    print(-1 if a > n else n - a)
    return


#main
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=map(int,input().split())
a=list(map(int,input().split()))
x=n-sum(a)
if(x>=0):
  print(x)
elif(x<0):
  print("-1")

Submission status: Accepted

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

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

Submission status: Accepted

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

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

Submission status: Accepted

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

sum = sum(A)
print(max([N-sum, -1]))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import numpy as np
import math
import scipy as sp
import queue
import collections

MOD = 10 ** 9 + 7
INF = 10 ** 9

def main(kwargs):
    n = kwargs["n"]
    m = kwargs["m"]
    A = kwargs["A"]
    res = max(-1, n - sum(A))
    return res

if __name__ == "__main__":
    kwargs = {}

    cin = input().split()
    #kwargs["n"] = cin[0]
    #kwargs["n"], kwargs["k"] = cin
    #kwargs["n"] = [int(i) for i in cin][0]
    kwargs["n"], kwargs["m"] = [int(i) for i in cin]
    cin = input().split()
    kwargs["A"] = [int(i) for i in cin]

    cout = main(kwargs)
    print(cout)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N, M = map(int, input().split(' '))
A = map(int, input().split(' '))
# 結果出力
tmp = N - sum(A)
print(-1 if tmp < 0 else tmp )

Submission status: Accepted

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

Submission status: Accepted

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

from sys import stdin, stderr

def main():
   N, M = map(int, stdin.readline().split())
   A = map(int, stdin.readline().split())

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

   return 0

if __name__ == '__main__': main()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from sys import stdin


def get_result(data):
    N, M = data[0]
    A = data[1]
    ans = N - sum(A)
    return ans if ans >= 0 else -1


if __name__ == '__main__':
    raw_data = [val.rstrip() for val in stdin.readlines()]
    data = [list(map(int, val.split(' '))) for val in raw_data]
    result = get_result(data)
    print(result)

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

Solution code:
#n=int(input())
n,m=map(int,input().split())
al=list(map(int,input().split()))
#l=[list(map(int,input().split())) for i in range(n)]

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

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

if __name__ == "__main__":
    main()

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

Submission status: Accepted

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

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
N,M=map(int,input().split())
home=list(map(int,input().split()))
ans,cal=0,0

for i in range(M):
    cal+=home[i]


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

Submission status: Accepted

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

a = [int(i) for i in 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()))

t = sum(a)

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

Submission status: Accepted

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

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

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

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

Submission status: Accepted

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

Submission status: Accepted

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

LEISURE = N - sum(A)

if LEISURE >= 0:
    print(LEISURE)

else:
    print(-1)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
if __name__ == "__main__":
    n, m = map(int, input().split())
    a = map(int, input().split())
    result = n - sum(a)
    print(result if result >= 0 else -1)

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
#abc163b
n,m=map(int,input().split())
a=list(map(int,input().split()))
res=n-sum(a)
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()))
print('-1' if sum(a) > n else n - sum(a))

Submission status: Accepted

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

Submission status: Accepted

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

days = 0
for a in A:
    days+=a

if N-days>=0:
    print(N-days)
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:
n, m = map(int, input().split())
a = list(map(int, input().split()))

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

print(ans)

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

Submission status: Accepted

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

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

Submission status: Accepted

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

for v in A:
	n -= v

print(n) if n >= 0 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)

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

Submission status: Accepted

Solution code:
n,m =(int(x) for x in input().split())
s = 0
a = input('').split()
for j in range(m):
    s =s+ int(a[j])
if (n>=s):
    print(n-s)
else:
    print('-1')

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
sum = 0
x = list(map(int, input().split()))

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

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

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:
import sys
stdin = sys.stdin
inf = 1 << 60
mod = 1000000007
 
ni      = lambda: int(ns())
nin     = lambda y: [ni() for _ in range(y)]
na      = lambda: list(map(int, stdin.readline().split()))
nan     = lambda y: [na() for _ in range(y)]
nf      = lambda: float(ns())
nfn     = lambda y: [nf() for _ in range(y)]
nfa     = lambda: list(map(float, stdin.readline().split()))
nfan    = lambda y: [nfa() for _ in range(y)]
ns      = lambda: stdin.readline().rstrip()
nsn     = lambda y: [ns() for _ in range(y)]
ncl     = lambda y: [list(ns()) for _ in range(y)]
nas     = lambda: stdin.readline().split()

n, m = na()
a = na()

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

Submission status: Accepted

Solution code:
n, m = [int(x) for x in input().split(" ")]
times = [int(x) for x in input().split(" ")]

s = sum(times)

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

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

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

Submission status: Accepted

Solution code:

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

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

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10000000)

#const
dxdy=((1,0),(0,1))
#my functions here!
def pin(type=int):
    return map(type,input().rstrip().split())
from math import gcd

#your code here!
def resolve():
    N,M=pin()
    A=(pin())
    t=(N)-sum(A)
    #print(t)
    ans=t if t>-1 else -1
    print(ans)

import sys
from io import StringIO
import unittest


class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)

    def test_入力例_1(self):
        input = """41 2
5 6"""
        output = """30"""
        self.assertIO(input, output)

    def test_入力例_2(self):
        input = """10 2
5 6"""
        output = """-1"""
        self.assertIO(input, output)

    def test_入力例_3(self):
        input = """11 2
5 6"""
        output = """0"""
        self.assertIO(input, output)

    def test_入力例_4(self):
        input = """314 15
9 26 5 35 8 9 79 3 23 8 46 2 6 43 3"""
        output = """9"""
        self.assertIO(input, output)


if __name__ == "__main__":
    #unittest.main()


    resolve()

Submission status: Accepted

Solution code:
n, _ = list(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 = sum(list(map(int, input().split())))
if n >= a:
    print(n - a)
else:
    print("-1")

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
lista=list(map(int,input().split()))
eq=0

for i in range(m):
  eq+=lista[i]

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

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**6)


############ ---- Input Functions ---- ############
def in_int():
    return (int(input()))


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


def in_str():
    s = input()
    return (list(s[:len(s) - 1]))


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

mod = 7 + 10**9

n, m = in_ints()

a = in_list()

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7 # 998244353
input=lambda:sys.stdin.readline().rstrip()
def resolve():
    n, m = map(int,input().split())
    A = list(map(int,input().split()))
    res = n - sum(A)
    res = max(res, -1)
    print(res)
resolve()

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
Days,works=map(int,input().split())
Time=list(map(int,input().split()))
Daysum=int(0)
for i in range(works):
  Daysum+=Time[i]
if Daysum<=Days:
  print(Days-Daysum)
else :
  print(-1)

Submission status: Accepted

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

counter = 0

for i in A:
    counter += i

result = N - counter
if result <= -1:
    print('-1')
else:
    print(result)

Submission status: Accepted

Solution code:
a1, b = [int(s) for s in input().split(" ")]
S=0
a= [int(s) for s in input().split(" ")]
for k in range(0,b):
    S=S+a[k]
if a1-S>= 0:
    print(a1-S)
else:
    print(-1)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Sun Apr 19 21:57:00 2020

@author: Kashem Pagla
"""


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

Submission status: Accepted

Solution code:
n,m,*l=[int(i) for i in open(0).read().split()]
print(max(-1,n-sum(l)))

Submission status: Accepted

Solution code:
a,b=map(int,input().split())
c=[int(x) for x in input().split()]
s=sum(c)
print(max(a-s,-1))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
a,b = map(int,input().split())
c = [int(x) for x in input().split()]
csum = 0
for i in range(len(c)):
    csum = csum + c[i]
if a>=csum:
    print(a-csum)
else:
    print(-1)

Submission status: Accepted

Solution code:
A,B=(int(x) for x in input().split())
S=list(map(int, input().split()))
C=sum(S)
if A>=C:
  print(A-C)
else:
  print(-1)

Submission status: Accepted

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


if __name__ == '__main__':
    solve()

Submission status: Accepted

Solution code:
a=input()
b=input()
c=a.split()
d=b.split()
e=int(c[0])
for i in range(int(c[1])):
  e=e-int(d[i])
if e < 0:
  print("-1")
else:
  print(e)

Submission status: Accepted

Solution code:
n,k = [int(x) for x in input().strip().split()]
a = [int(x) for x in input().strip().split()]
print(max(-1, n - sum(a)))

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:
a, _ =map(int,input().split())
li = [int(x) for x in input().split()]
s = sum(li)
print(max(a-s, -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:
m,n=map(int,input().split())
s=list(map(int,input().split()))
sum_s=sum(s)
ans=m-sum_s
if ans>=0:
  print(ans)
else:
  print(-1)

Submission status: Accepted

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

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

Submission status: Accepted

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

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

Submission status: Accepted

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

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

print(N-Ans if Ans<=N else -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(max([n,-1]))

Submission status: Accepted

Solution code:
n,m = [int(x) for x in input().split()]
arr = sum([int(x) for x in input().split()])

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#!usr/bin/env python3
from collections import defaultdict, deque
from heapq import heappush, heappop
from itertools import permutations, accumulate
import sys
import math
import bisect
def LI(): return [int(x) for x in sys.stdin.buffer.readline().split()]
def I(): return int(sys.stdin.buffer.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

def solve():
    n,m = LI()
    a = LI()
    ans = n-sum(a)
    if ans < 0:
        print(-1)
    else:
        print(ans)
    return

#Solve
if __name__ == "__main__":
    solve()

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
a,b=[int(i) for i in input().split()]
arr=[int(i) for i in input().split()]
print(max(a-sum(arr),-1))

Submission status: Accepted

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

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

ans = N

for a in A:
  ans -= a

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

Submission status: Accepted

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

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