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

Solution (Python):
NM = [int(i) for i in input().split()]
A = [int(i) for i in input().split()]

N = NM[0]
M = NM[1]

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

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

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

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

Solution (Python):
import sys
N, M = map(int, sys.stdin.readline().split())
A = list(map(int, sys.stdin.readline().split()))

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

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

if N - sum(homeworks) < 0:
    holiday = -1
else :
    holiday = N - sum(homeworks)
    
print(holiday)

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

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

Solution (Python):
n = [list(map(int, input().split())) for i in range(2)]

N = n[0][0]
M = n[0][1]
A = n[1]
days = 0
for i in A:
    days += i

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

Solution (Python):
from collections import defaultdict, deque
import sys
import heapq
import bisect
import itertools
import queue
import copy
import time
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7

def inp(): return int(sys.stdin.readline())

def inpl(): return list(map(int, sys.stdin.readline().split()))

def inpl_str(): return list(sys.stdin.readline().split())

N, M = inpl()
A = inpl()
days = sum(A)
if N - days >= 0:
    print(N-days)
else:
    print(-1)

Solution (Python):





import sys,os
from io import BytesIO, IOBase
import collections,itertools,bisect,heapq,math,string


BUFSIZE = 8192

BUFSIZE = 8192

class FastIO(IOBase):
    newlines = 0

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

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

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

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


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


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

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

Solution (Python):

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

Solution (Python):
import numpy as np

N,M = input().split()
N = int(N)
A = np.array(input().split()).astype(int)

print(np.maximum(N-sum(A), -1))

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

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

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

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


sum = 0

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

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

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

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

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



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

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

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

Solution (Python):


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

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

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

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

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

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

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

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

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

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

x = sum(A)

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

Solution (Python):
from sys import stdin

n, m = [int(x) for x in stdin.readline().rstrip().split()]
a_sum = sum([int(x) for x in stdin.readline().rstrip().split()])

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

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

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

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

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

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

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

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

Solution (Python):


input_line = input().split()
N = int(input_line[0])
M = int(input_line[1])
count = 0
line = input().split()
for i in range(M):
    count+=int(line[i])
    
if N - count <= -1:
    print(-1)
    
    
else:
    print(N - count)

Solution (Python):
homework = list(map(int, input().split(' ')))
days = list(map(int, input().split(' ')))
day_sum = 0

for i in range(len(days)):
    day_sum += days[i]

if homework[0] - day_sum < 0:
    print(-1)
else:
    print(homework[0] - day_sum)

Solution (Python):

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

sum_a = sum(a)

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

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

if N - sum(dias) < 0:
    print(-1)

elif N - sum(dias) >= 0:
    print(N - sum(dias))

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

Solution (Python):
N, _ = [int(n) for n in input().split()]
for A in input().split():
    N -= int(A)
if N < 0:
    N = -1
print(N)

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

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

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

Solution (Python):
import numpy as np
N, M = map(int, input().split())
A_list = np.array(list(map(int, input().split())))

total = np.sum(A_list)
free_day = max(N - total, -1)
print(free_day)

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

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

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

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

Solution (Python):
N,M=map(int,input().split())
A=[int(i) for i in input().split()]
print(max(N-sum(A),-1))

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

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

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

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

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

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

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

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

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

a = input().split()
for i in range(len(a)):
	a[i] = int(a[i])
	
if n >= sum(a):
	print(n-sum(a))
else:
	print(-1)

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

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

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

Solution (Python):
n, _ = map(int, input().split())
a = n - eval(input().replace(' ', '+'))
print([-1,a][a >= 0])

Solution (Python):
def main():
    from builtins import int, map, list, print
    import sys
    sys.setrecursionlimit(10 ** 6)

    input = sys.stdin.readline
    input_list = (lambda: input().rstrip().split())
    input_number = (lambda: int(input()))
    input_number_list = (lambda: list(map(int, input_list())))

    N, M = input_number_list()
    A = sum(input_number_list())
    ans = N - A
    print([ans, -1][ans < 0])


if __name__ == '__main__':
    main()

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

Solution (Python):
import  math
d=input().split()
a,b=int(d[0]),int(d[1])
c=[int(a) for a in input().split()]
for i in c:
    a-=i
if(a<0):
    print(-1)
else:
    print(a)

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

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

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

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

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

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

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

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

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

Solution (Python):


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

daystr = input().split()
homeworks = []
for s in daystr:
    homeworks.append(int(s))

days = sum(homeworks)
playable_days = n - days
if playable_days < 0:
    print(-1)
else:
    print(playable_days)

Solution (Python):
from collections import deque
import math; floor,ceil = math.floor,math.ceil
import sys; input = lambda: sys.stdin.readline().rstrip()
aint = lambda: int(input()); ints = lambda: list(map(int, input().split()))
Yes = lambda boolean: print('Yes') if boolean else print('No')
YES = lambda boolean: print('YES') if boolean else print('NO')
is_even = lambda x: True if x%2==0 else False

def main():
  n,m = ints()
  a = ints()
  s = sum(a)
  print(max(-1,n-s))

if __name__ == '__main__':
  main()

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

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

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

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

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

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

zip=zip 
def linp(x):
    return list(map(int,x.split()))
def minp(x):
    return map(int,x.split())

n,m=minp(inp())
a=linp(inp())
an=n-sum(a)
if an>=0:
    print(an)
else:
    print("-1")

Solution (Python):

import sys


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



def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  
    M = int(next(tokens))  
    A = [int(next(tokens)) for _ in range(M)]  
    solve(N, M, A)

if __name__ == '__main__':
    main()

Solution (Python):

import sys


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



def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  
    M = int(next(tokens))  
    A = [int(next(tokens)) for _ in range(M)]  
    solve(N, M, A)

if __name__ == '__main__':
    main()

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

Solution (Python):

import sys


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



def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  
    M = int(next(tokens))  
    A = [int(next(tokens)) for _ in range(M)]  
    solve(N, M, A)

if __name__ == '__main__':
    main()

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

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

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

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

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

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

Solution (Python):

def inputlist(): return [int(k) for k in input().split()]

N,M = inputlist()
A =inputlist()
s =sum(A)
if N<s:
    print(-1)
else:
    print(N-s)

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

Solution (Python):
if __name__ == '__main__':
    x=list(map(int,input().split(" ")))
    y = list(map(int, input().split(" ")))
    num=0
    for i in y:
        num+=i
    if x[0]<num:
        print(-1)
    else: print(x[0]-num)

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

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

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

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

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

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

print(N - cost if cost <= N else -1)

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

ans=0
sum1=0
for i in range(0,M):
  sum1+=A[i]

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

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

ans = n - (sum(a))

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

Solution (Python):
import sys
from collections import deque
import math

input = sys.stdin.readline


def solve():
    n_days, n_hw = map(int, input().split())
    a = list(map(int, input().split()))
    n_days_left =  n_days - sum(a)

    if n_days_left < 0:
        return -1
    else:
        return n_days_left



if __name__ == '__main__':
    answer = solve()
    print(answer)

Solution (Python):
days, num = map(int, input().split())
hwk = map(int, input().split())
hwk_days = sum(hwk)
if days >= hwk_days:
  print(days - hwk_days)
else:
  print(-1)

Solution (Python):

import sys
import math
import numpy as np

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

cost = sum(A)

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

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

homework = sum(A) 
print(n - homework if n - homework >= 0 else -1)

Solution (Python):
import math
def main():

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

    v = sum(A)
    if N >= v: return N-v
    return -1

if __name__ == '__main__':
    print(main())

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

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

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

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

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

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

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

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

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

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

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

Solution (Python):


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

for i in a:
    n -= int(i)

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

Solution (Python):
summer_vacation_day, home_work_number = input().split()
take_time_home_work = input().split()
result  = 0

for i in range(int(home_work_number)):
  result = result + int(take_time_home_work[i])

if int(summer_vacation_day) - result >= 0:
  print(int(summer_vacation_day) - result)
else:
  print('-1')

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

goukei = sum(A)

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

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



for i in a:
    s += i
ans = n - s
if ans < 0:
    ans = -1
print(ans)

Solution (Python):
n,m = map(int, input().split())
a = input().split()
num = 0
s = 0
while num != (m):
    s += int(a[num])
    num += 1
ans = n - s
if ans < 0:
    ans = -1
print(ans)

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


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


ans=0
for i in alist:
  ans+=i

if ans>a:
  print(-1)
else:
  print(a-ans)

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

all_done_days = sum(a_list)

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

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

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

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

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

Solution (Python):


"""
Created on Sun Apr 26 13:55:09 2020

@author: hiroki
"""


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

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

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

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

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

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

Solution (Python):

DATA = """
314 15
9 26 5 35 8 9 79 3 23 8 46 2 6 43 1000
""".split("\n")

def get_debug_line():
	for i in DATA:
		yield i

if 1:
	get_line = input
else:
	get_line = get_debug_line().__next__
	get_line()

N, M = [int(i) for i in get_line().strip().split(" ")]
A = [int(i) for i in get_line().strip().split(" ")]

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

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

Solution (Python):
N,M = [int(x) for x in input().split()]
A = [int(x) for x in input().split()]
n=N-sum(A)
if n < 0:
  print(-1)
else:
  print(n)

Solution (Python):
s1 = input().split()
s2 = input().split()

N = int(s1[0])
M = int(s1[1])
list_of_A = s2
for i in range(0,len(list_of_A)):
    list_of_A[i] = int(list_of_A[i])

daysTotal = 0
for i in range(0,len(list_of_A)):
    daysTotal += list_of_A[i]

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

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

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

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

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

a_sum = sum(a);

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

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

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

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

Solution (Python):
n,m = map(int,input().split())
b=input().split()
b_int = [int(i) for i in b]

ho=0

for a in range(m):
    ho = ho + b_int[a]

if n-ho <0:
    ans = -1
else:
    ans = n-ho

print(str(ans))

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

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

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

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

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

day_count = n-c_sum

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

Solution (Python):
n , m = input().split()
s = input().split()
cnt = 0
for i in s :
	i = int(i)
	cnt += i

rest_day = int(n) - cnt
if rest_day < 0:
  rest_day = -1
print(rest_day)

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

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

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

day_count = N-c_sum

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

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

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

day_count = N-c_sum

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

Solution (Python):
x = list(map(int, input().split()))
valor = list(map(int, input().split()))
z=0
for i in valor:
    z=i+z
if(z>x[0]):
    print(-1)
elif(z==x[0]):
    print(0)
else:
    print(x[0]-z)

Solution (Python):
if __name__ == '__main__':
	N, M = map(int, input().split())
	A = [int(a) for a in input().split()]
	d = int(N - sum(A))
	if d < 0:
		print(-1)
	else:
		print(d)

Solution (Python):
n,m=map(int,input().split())
a=[int(b) for b in input().split()]
def func(n,a):
    if n< sum(a):return "-1"
    else: 
        return n-sum(a)
print(func(n,a))

Solution (Python):
n,m=map(int,input().split())
a=[int(b) for b in input().split()]
def func(n,a):
    if n< sum(a):return "-1"
    else: 
        return n-sum(a)
print(func(n,a))

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

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

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

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

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

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

homework = list(map(int, input().strip().split(" ")))

day = n - sum(homework)

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

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

n = s1[0]
m = s1[1]

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

lt = 0

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

ld = n - lt

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

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

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

Solution (Python):
from math import pi

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

if __name__ == "__main__":
    main()

Solution (Python):


import math
n, m = map(int, input().split())
ans = 0
a = list(map(int, input().split()))
for i in range(m):
    ans +=a[i]
ans= max(n-ans, -1);
print(ans)

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

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

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

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

Solution (Python):

import math

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




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

Solution (Python):
N,M=map(int,input().split())
P=[*map(int,input().split())]
if(sum(P)>N):
  print(-1)
else:
  print(N-sum(P))

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

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

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

plays = n - sum(works)
print(plays if plays >= 0 else -1)

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

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

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

playday = n - sum(days)

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

Solution (Python):
data = input().rstrip().split(" ")
day = int(data[0])
task = int(data[1])
need = 0
hw = input().rstrip().split(" ")
for i in range(task):
    need += int(hw[int(i)])
answer = day - need
if answer >= 0:
    print(answer)
else:
    print("-1")

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

d = n - sum(a)

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

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

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

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