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

Solution (Python):
import bisect
import copy
import heapq
import sys
import itertools
import math
import queue
input = sys.stdin.readline
sys.setrecursionlimit(1000000)
mod = 10 ** 9 + 7

def read_values(): return map(int, input().split())
def read_index(): return map(lambda x: int(x) - 1, input().split())
def read_list(): return list(read_values())
def read_lists(N): return [read_list() for n in range(N)]
def init_dp1(init, N): return [init for _ in range(N)]
def init_dp2(init, N, M): return [[init for _ in range(M)] for _ in range(N)]


class V:
    def __init__(self, f, v=None):
        self.f = f
        self.v = v
 
    def __str__(self):
        return str(self.v)
 
    def ud(self, n):
        if n is None:
            return

        if self.v is None:
            self.v = n
            return
        self.v = self.f(self.v, n) 


def main():
    N, M = read_values() 
    A = read_list()

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


if __name__ == "__main__":
    main()

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

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

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

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

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

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

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

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

Solution (Python):
import sys
import math
import bisect

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

if __name__ == "__main__":
    main()

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

N = int(N)
M = int(M)

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


if sum(a) < N:
    print(N-sum(a))

if sum(a) == N:
    print(0)

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

Solution (Python):
a,b = map(int,input().split())
l = list(map(int,input().split()))
s = sum(l)

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

Solution (Python):


s = [input() for i in range(2)]
n = int(s[0].split()[0])
m = int(s[0].split()[1])
a = list(map(int, s[1].split()))

for i in range(0, m):
    n = n - a[i]
    if n < 0:
        n = -1
        break

print(n)

Solution (Python):
from sys import stdin, setrecursionlimit, stdout

from collections import deque
from math import sqrt, floor, ceil, log, log2, log10, pi, gcd, sin, cos, asin
def ii(): return int(stdin.readline())
def fi(): return float(stdin.readline())
def mi(): return map(int, stdin.readline().split())
def fmi(): return map(float, stdin.readline().split())
def li(): return list(mi())
def lsi():
    x=list(stdin.readline())
    x.pop()
    return x
def si(): return stdin.readline()
mod=1000000007
res=['YES', 'NO']

n, m=mi()
a=li()
print(max(-1, n-sum(a)))

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

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

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

Solution (Python):
vacDuration, homeworkAmount = map(int, input().split())
daySpent = list(map(int, input().split()))
sum_daySpent = 0
for i in daySpent:
    sum_daySpent += i
if sum_daySpent > vacDuration:
    print('-1')
else:
    print(vacDuration - sum_daySpent)

Solution (Python):
N, M = map(int, input().split())
A = input().split()
A_int = [int(n) for n in A]

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

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


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

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

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

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

Solution (Python):
n_vacations, n_an = list(map(int, input().split()))
an = list(map(int, input().split()))
out = n_vacations - sum(an) 
if out < 0:
  print("-1")
else:
  print(out)

Solution (Python):
import sys

days, N = map(int, sys.stdin.readline().split())

a = list(map(int, sys.stdin.readline().split()))

ans = int(days - sum(a))

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

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

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

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

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

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

Solution (Python):
a,b=map(int,input().split())
nums = [int(e) for e in input().split()]
all=sum(nums)
if a > all:
	print (a-all)
elif a == all:
	print (0)
else:
	print (-1)

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

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

Solution (Python):
import math

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

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

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

Solution (Python):
import sys
import math
from collections import defaultdict
from bisect import bisect_left, bisect_right

sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]

mod = 10**9 + 7

def I(): return int(input())
def LI(): return list(map(int, input().split()))
def LIR(row,col):
    if row <= 0:
        return [[] for _ in range(col)]
    elif col == 1:
        return [I() for _ in range(row)]
    else:
        read_all = [LI() for _ in range(row)]
        return map(list, zip(*read_all))



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

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

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

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

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

Solution (Python):
def homework(M,array):
  if sum(array) > M:
    return -1
  else:
    return M - sum(array)


M,N = map(int,input().split())
array = list(map(int, input().split()))
print(homework(M,array))

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

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

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

ar=list(map(int,input().split()))
s=sum(ar)

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

Solution (Python):
N, M = map(int, input().split())
A = map(int, input().split())
hw = 0
for i in A:
    hw += i
ans = N - hw

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

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

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

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

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

Solution (Python):
A = input().split(" ")
B = input().split(" ")
b = 0
s = 0

for i in range(int(A[1])):
  s = s + int(B[b])
  b += 1

if int(A[0]) >= s:
  print(int(A[0]) - s)
else:
  print(-1)

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

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

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

a_sum=0

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

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

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):
input_= list(map(int, input().split()))
timeofholiday=input_[0]
sum=0
homework_num=input_[1]
que=list(map(int, input().split()))
for i in que:
  sum+=i
  
if sum > timeofholiday:
  print("-1")
else:
  print(timeofholiday-sum)

Solution (Python):
N, M = map(int, input().split())
a = input().split()
list_i = [int(b) for b in a]

ret = N - sum(list_i)
if ret < 0:
  ret = -1
print(ret)

Solution (Python):
import sys
import os
import math

def file_input():
    f = open('input.txt', 'r')
    sys.stdin = f

def main():
    

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

    for i in range(M):
        for j in range(A[i]):
            N -= 1
            if N==-1 :
                break
        else:
            continue
        break

    print(N)


if __name__ == '__main__':
    main()

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

all_homework_day = sum(a)

if all_homework_day <= n:
    play_day = n - all_homework_day
else:
    play_day = -1

print(play_day)

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

Solution (Python):
N, M = map(int, input().split())
numbers_list = input().split(' ')
homework_sum = 0
for i in range(0, M):
  homework_sum = homework_sum + int(numbers_list[i])
play_day = N - homework_sum
if play_day >= 0:
  print(play_day)
else:
  print(-1)

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

Solution (Python):
import random

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


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

N = s[1]

if s[0]-sum(a) >= 0:
  print(s[0]-sum(a))
else:
  print("-1")

Solution (Python):
input1 = input()
daylist = input1.split()
days = daylist[0]

input2 = input()
tasklist = input2.split()

sum = 0
for task in tasklist:
  sum += int(task)

calc = int(days) - sum
if calc >= 0:
  print(calc)
else:
  print("-1")

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

A = input().split(" ")

total = 0

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

play = N - total
if play < 0:
  play = -1

print(play)

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

Solution (Python):

N, M = map(int, input().split())
work = []
[work.append(x) for x in map(int, input().split())]

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

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

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

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

Solution (Python):
N,M=[int(e) for e in input().split(' ')]
As=[int(e) for e in input().split(' ')]

ans = N - sum(As)
if ans < 0:
    ans = -1
print(ans)

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

total = 0
for n in range(int(M)):
    total += int(A[n])

ans = -1 if total > int(N) else int(N)-total
print(ans)

Solution (Python):
def function(n, list1):
  total = sum(list1)
  if n >= total:
    return n - total
  else:
    return -1
  
line1 = input().split()
n = int(line1[0])
line2 = input().split()
list1 = [int(i) for i in line2]
print(function(n, list1))

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

Solution (Python):

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

sm = sum(arr)

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

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())
s=0
for i in input().split():
    s=s+int(i)
if s>n:
    print("-1")
else:
    print(n-s)

Solution (Python):
import sys

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

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

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

print(N-sum(A))

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

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


N = data[0] 
M = data[1] 

A = 0 

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


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

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

Solution (Python):
a = input().split()

N = int(a[0])


c = input().split()



d = 0
  
for i in c:
  d += int(i)

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

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):
a,b = map(int,input().split())
li = []
li = [int(j) for j in input().split()]


c = sum(li)

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

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

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

Solution (Python):
n, m = tuple(int(s) for s in input().split())
arr = list(int(s) for s in input().split())

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

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

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

num = 0
for i in range(0, len(a)):
    num += int(a[i])

target = n - num

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

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

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

vacation_day = n - sum(hw)

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

Solution (Python):

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

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

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

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


total = 0

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

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

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

Solution (Python):
n, m = (int(i) for i in input().split())
a = [int(i) for i in input().split()]
print(max(n - sum(a), -1))

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

days = sum(As)

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

Solution (Python):
def MI(): return map(int, input().split())
def LI(): return list(MI())

if __name__ == "__main__":
    N, M = MI()
    A = sum(LI())
    print(N-A if N >= A else -1)

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

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

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

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

Solution (Python):
from operator import add
import functools


n = input().split(" ")

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

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

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

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

Solution (Python):
import numpy as np


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

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

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

goukei = sum(A_list)

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

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

Solution (Python):
import sys

def main():

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

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

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

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

Ai_sum = sum(Ai_list)

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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


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

x = int(N)

for j in range(int(M)):
    x = x - int(A[j])
    j += 1

if x < 0 :
    print(-1)

else :
    print(x)

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

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

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

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

d = sum(c)

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

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

a = N - sum(list)

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

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

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

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

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

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

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

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

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

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

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

Solution (Python):

import math

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

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

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

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

Solution (Python):

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

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

totalwork = sum(works)

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

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

s = sum(A)

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

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

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

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

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

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

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

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

cnt = 0

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

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

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

Solution (Python):

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

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

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

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

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

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

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

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

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):
def q2():
    N, M = (int(i) for i in input().split())
    A = [int(i) for i in input().split()]
    sum_A = sum(A)
    if N >= sum_A:
        ans = N - sum_A
    else:
        ans = -1
    print(ans)


if __name__ == '__main__':
    q2()

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

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

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

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

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

Solution (Python):
import math

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


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

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

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

Solution (Python):


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

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

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

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

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

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

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

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

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

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 = [i for i in map(int, input().split())]

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

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

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


for k in range(m):

    n=n-int(a[k])

    if n < 0:
        n=-1
        break

print(n)

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

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

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

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

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

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

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

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

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

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

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