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):
array = []

for i in range(2):
    val = input()
    array.append(val.split())

summar_days = int(array[0][0])
amount_homework = int(array[0][1])

if amount_homework != len(array[1]):
    print("Error: M is different than length of A")
    exit()

for need_days in array[1]:
    summar_days = summar_days - int(need_days)
    if summar_days < 0:
        summar_days = -1
        break

print(summar_days)

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

"""
Created on Wed May  6 00:38:38 2020

@author: shinba
"""

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

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

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

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

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

if sum(v) <= n:
    print(n - sum(v));
else:
    print("-1");

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

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


total = 0
for a in List:
  
  total = total + a

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

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

n = int(a[0])
m = int(a[1])

y = input().split()

x = [int(i) for i in y]

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

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

whole_day = N - sum(A)

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

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

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

Solution (Python):
print(-1 if (d := tuple(map(int, input().split()))[0] - sum(map(int, input().split()))) < 0 else d)

Solution (Python):
n, m = map(lambda x: int(x), input().split())
days = n - sum(map(lambda x: int(x), input().split()))
print(days) if days >= 0 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())
A=list(map(int,input().split()))

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

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

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

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

s = sum(tasks)

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

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

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

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

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

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

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

Solution (Python):
import math

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):
import numpy as np

def calculate_free_day(summer_days, need_days):
    return summer_days - np.sum(need_days)

if __name__ == "__main__":
    summer = int(input().split()[0])
    need = np.array([int(i) for i in input().split()])
    free_day = calculate_free_day(summer, need)

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

Solution (Python):
import math
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=input().split()
A=input().split()

if int(N)-sum(list(map(int,A)))>=0:
    print(int(N)-sum(list(map(int,A))))
else:
    print("-1")

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

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

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

if hw > N:
  print("-1")
else:
  print(N-hw)

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


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

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

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

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

Solution (Python):
import sys
sys.setrecursionlimit(10 ** 6)

int1 = lambda x: int(x) - 1
def II(): return int(input())

def MI(): return map(int, input().split())
def MI1(): return map(int1, input().split())

def LI(): return list(map(int, input().split()))
def LI1(): return list(map(int1, input().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]

INF = float('inf')

def solve():
    n, m = MI()
    A = LI()

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


if __name__ == '__main__':
    solve()

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

sum = sum(a_)
res = n - sum

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

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

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

Solution (Python):

import sys


def solve(N: int, M: int, A: "List[int]"):
    print(max(-1, N - sum(A)))
    return



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

if __name__ == '__main__':
    main()

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

Solution (Python):
NM = list(map(int, input().split()))
N, M = NM[0],NM[1]
a = list(map(int, input().split()))

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

Solution (Python):
NM = list(map(int, input().split()))
a = list(map(int, input().split()))
x = 0
for i in range(NM[1]):
    x += a[i]

if x > NM[0]:
    print(-1)
else:
    print(NM[0] - x)

Solution (Python):
NM = list(map(int, input().split()))
N, M = NM[0],NM[1]
a = list(map(int, input().split()))
x = 0
for i in range(M):
    x += a[i]

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

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

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

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

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

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

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

for i in range(M):
    N -= a[i]

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

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

for i in range(a[1]):
  c = c + b[i]

if a[0] - c < 0:
  print(-1)
else:
  print(a[0] - c)

Solution (Python):
x, y = map(int, input().split())
A = list(map(int, input().split()))

for num in range(y):
    x -= A[num]

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

Solution (Python):

N,M = map(int, input().split())
A = list(map(int, input().split()))
f_days = N - sum(A)
if f_days >= 0:
    print(f_days)
else:
    print(-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())
h = map(int, input().split())
H = list(h)
for days in H:
  n -= days
if n>=0:
  print(n)
if n<0:
  print("-1")

Solution (Python):
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop
from itertools import permutations, accumulate
from math import sqrt, ceil, floor
from bisect import bisect_left, bisect_right
from copy import deepcopy
from operator import itemgetter
from fractions import gcd
import sys
def I(): return int(input())  
def Is(): return map(int, input().split())  
def LI(): return list(map(int, input().split()))  
def TI(): return tuple(map(int, input().split()))  
def IR(n): return [I() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def TIR(n): return [TI() for _ in range(n)]
def S(): return input()
def Ss(): return input().split()  
def LS(): return list(input())  
def SR(n): return [S() for _ in range(n)]
def SsR(n): return [Ss() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
sys.setrecursionlimit(1000000)
MOD = 1000000007
INF = float('inf')

n, m = Is()
A = LI()

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

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

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

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

Solution (Python):

inp_ls = input().split(" ")
n,m = [int(e) for e in inp_ls[:2]]
inp_a_ls = input().split(" ")
a_ls = [int(e) for e in inp_a_ls[:m]]


rest = n - sum(a_ls)
out = rest if rest >= 0 else -1


print(out)

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

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

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

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

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):
import sys
import math
def i():return int(sys.stdin.readline().replace("\n",""))
def i2():return map(int,sys.stdin.readline().replace("\n","").split())
def s():return str(sys.stdin.readline().replace("\n",""))
def l():return list(sys.stdin.readline().replace("\n",""))
def intl():return [int(k) for k in sys.stdin.readline().replace("\n","").split()]
def lx():return list(map(lambda x:int(x)*-1,sys.stdin.readline().replace("\n","").split()))
def t():return tuple(map(int,sys.stdin.readline().replace("\n","").split()))

def main():
    n,m = i2()
    a = intl()
    print(n-sum(a) if n - sum(a) >= 0 else -1)
if __name__ == "__main__":
    main()

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

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

a_sum = sum(A_list)
playday = N-a_sum

if playday < 0:
    print(-1)

else:
    print(playday)

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

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

homework_day=0

for i in a:
    homework_day+=i

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

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

Solution (Python):
n, m = map(int, input().split())
l = input().split()
days = 0
for i in l:
  days += int(i)
remain = n-days
if remain <= -2:
  remain = -1
print(remain)

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

Solution (Python):
n, m = list(map(int, input().rstrip().split()))
total = sum([int(i) for i in input().rstrip().split()])
result = -1 if n < total else n - total
print(result)

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

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

for day in A:
    n -= day

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

Solution (Python):
N, M = map(int,input().split())
lst = list(map(int, input().split()))
days = N-sum(lst)
if days >=0:
  print(days)
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(ans)
else:
    print(-1)

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

Solution (Python):

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

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

Solution (Python):
import sys
rs = lambda: sys.stdin.readline().rstrip()
ri = lambda: int(rs())
lrs = lambda: [_ for _ in rs().split()]
lri = lambda: [int(_) for _ in rs().split()]

N, M = lri()
A = lri()
print(max(N - sum(A), -1))

Solution (Python):

import sys
import math

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

if __name__ == '__main__':
    main()

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

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

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

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

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

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

Solution (Python):
x = input().split()
y = input().split()
n = int(x[0])
m = int(x[1])
count = 0
for i in y:
  count += int(i)
if (n - count) >= 0:
  print(n-count)
else:
  print('-1')

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

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

Solution (Python):
import math

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

    return 0

if __name__ == '__main__':
    main()

Solution (Python):
num_vacation_days, num_homework = map(int, input().split())
day_homework_costs = map(int, input().split())

for day_homework_cost in day_homework_costs:
    num_vacation_days -= day_homework_cost
    if num_vacation_days < 0:
        num_vacation_days = -1
        break

print(num_vacation_days)

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())
List = list(map(int,input().split()))
print(N-sum(List) if N-sum(List) >= 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()))

sub = N - sum(A)

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

Solution (Python):

import sys


def solve(N: int, M: int, A: "List[int]"):
    print(N - sum(A) if N - sum(A) >= 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):
def resolve():
    n, m = map(int, input().split())

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

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

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

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

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

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

print(ans)

Solution (Python):

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

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

if n>=0:
    print(n)

else:
    print(-1)

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

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

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

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

n=n-sum
if n<=-2:
  n=-1

print(n)

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

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

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

Solution (Python):
dias,tareas=input().split()
dias=int(dias)
tareas=int(tareas)
todas=input().split()
suma=0
for cada in todas:
    suma+=int(cada)
if suma<=dias:
    print(dias-suma)
else:
    print(-1)

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

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

for a in A:
    N -= a

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

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


s = n -sum(a)

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

Solution (Python):
vacation, homework = map(int, input().split())
daysList = []
days = list(map(int, input().split()))
for i in range(homework):
    daysList.append(days[i])
play_days = vacation - sum(daysList)

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

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

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

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

days = N - sum(A)

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

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

Solution (Python):
n, m =map(int,input().split())
s = list(map(int,input().split()))
free = n
i = 0
while i < m :
     free -= s[i]
     if free < 0 :
          break
     i += 1
if free < 0 :
     print("-1")
elif free >= 0 :
     print(str(free))

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

Solution (Python):


inp = input().split(' ')
N = int(inp[0])
M = int(inp[1])

inp = input().split(' ')
Am = [int(i) for i in inp]

residue = N - sum(Am)
print(residue if residue >= 0 else -1)

Solution (Python):
x = input()
space_index1 = x.index(' ')

n = int(x[0:space_index1])
m = int(x[space_index1+1:])

x = input()
tmp_space_idx = 0
Ajs = x.split(' ')

sum_ = 0
for aj in Ajs:
  sum_ += int(aj)

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

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

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

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

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

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

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

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

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

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

Solution (Python):
nums = input().split(' ')
vals = input().split(' ')
num2 = []
val2 = []

for i in range(len(nums)):
  num2.append(int(nums[i]))

for i in range(len(vals)):
  val2.append(int(vals[i]))

sum = 0

for val in val2:
  sum += val

if (sum > num2[0]):
  print("-1")

else:
  print(num2[0] - sum)

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

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

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

Solution (Python):
X, Y  = input().split()
sum = 0
Y2 = input().split()
for i in range(0, int(Y)):
  sum += int(Y2[i])

if int(X)-sum >= 0:
  print(int(X)-sum)
else:
  print(-1)

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

Solution (Python):
n,m=(int(i) for i in input().split())
t = [int(i) for i in input().split()]
s = sum(t)
if n>=s:
  print(n-s)
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(ans)
else:
  print("-1")

Solution (Python):
import numpy as np

A=list(input().split())


N=int(A[0])
M=int(A[1])

B=list(input().split())

k=0

for i in range(len(B)):
    k+=int(B[i])

print(N-k if N-k>=0 else -1)

Solution (Python):
[n,m]=list(map(int,input().split()))
alist=list(map(int,input().split()))
work=sum(alist)
ans=n-work
if ans<0:
    ans=-1
print(ans)

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

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

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

Solution (Python):
import math

def read_int():
    return int(input().strip())


def read_ints():
    return list(map(int, input().strip().split(' ')))


def solve():
    N, M = read_ints()
    A = read_ints()
    assignment_days = sum(A)
    return -1 if assignment_days > N else N-assignment_days


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

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

Sum = 0
for i in range(n):
  Sum +=b[i]

if Sum <= a[0]:
  print(a[0]-Sum)
else:
  print(-1)

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

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

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

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

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

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

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

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:
    break
if N < 0:
  print(-1)
else:
  print(N)

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

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

s = sum(A)

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

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

    print(max(N-sum(A),-1))
if __name__=="__main__":
    main()

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

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

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

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

ans = N - sum(A_list)

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

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

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

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

homework = sum(a)

if homework > N:
    print("-1")

else:
    print(N - homework)

Solution (Python):
s = input().split()
N=int(s[0])
M=int(s[1])
A=input().split()


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

Answer = N-sum

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

Solution (Python):


import sys
readline = sys.stdin.readline
read = sys.stdin.read
 
 
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())


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


S = sum(A)



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

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

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

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

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

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

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

hwdsum=0
k=0
while k<= m-1:
  hwdsum += a[k]
  k+=1
  
if n-hwdsum>=0:
  print(str(n-hwdsum))
  
else:
  print(str(-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_data = input()
a = a_data.split(' ')

sum = 0

for item in a:
  sum += int(item)

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