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

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

Solution (Python):
import math
N,M = map(int, input().split())
As = list(map(int, input().split()))
s = sum(As)

ans = max(-1,N - s)
print(ans)

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, *a = map(int, open(0).read().split())
print(max(n - sum(a), -1))

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

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

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

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

print(ans)

Solution (Python):

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


submit()

Solution (Python):


import sys
stdin = sys.stdin

def ns(): return stdin.readline().rstrip()
def ni(): return int(ns())
def na(): return list(map(int, stdin.readline().split()))

def main():
    n, m = na()
    a = na()
    ans = n - sum(a)
    print(ans if ans >= 0 else -1)

if __name__ == "__main__":
    main()

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

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

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

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

total = sum(A)
ans = N - total

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

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

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):
import sys
input = sys.stdin.readline

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

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

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


if __name__ == '__main__':
    main()

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

print(n-sum(A))

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


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

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

n, m = get_ints()
a = get_ints()
total = sum(a)
print(n - total if total <= n else -1)

Solution (Python):
n,m,*a=map(int,open(0).read().split())
s=sum(a)
print(max(-1,n-s))

Solution (Python):
import math
from functools import reduce
from collections import deque
import sys
sys.setrecursionlimit(10**7)


def get_nums_l():
    return [ int(s) for s in input().split(" ")]


def get_nums_n(n):
    return [ int(input()) for _ in range(n)]


def get_all_int():
    return map(int, open(0).read().split())

def log(*args):
    print("DEBUG:", *args, file=sys.stderr)

n,m,*A = get_all_int()
ans = n - sum(A)
print(ans if ans >= 0 else -1)

Solution (Python):
"""
// Author : snape_here - Susanta Mukherjee
     
 """
 
from __future__ import division, print_function
 
import os,sys
from io import BytesIO, IOBase
 
if sys.version_info[0] < 3:
    from __builtin__ import xrange as range
    from future_builtins import ascii, filter, hex, map, oct, zip
 
 
def ii(): return int(input())
def si(): return input()
def mi(): return map(int,input().split())
def li(): return list(mi())
 
 
def read():
    sys.stdin = open('input.txt', 'r')  
    sys.stdout = open('output.txt', 'w') 
 
def gcd(x, y):
    while y:
        x, y = y, x % y
    return x

mod=1000000007

import math

import bisect

abc="abcdefghijklmnopqrstuvwxyz"

def main():

    n,m=mi()
    a=li()
    s=sum(a)
    if s>n:
        print(-1)
    else:
        print(n-sum(a))

        


 
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")
 
 
def print(*args, **kwargs):
    """Prints the values to a stream, or to sys.stdout by default."""
    sep, file = kwargs.pop("sep", " "), kwargs.pop("file", sys.stdout)
    at_start = True
    for x in args:
        if not at_start:
            file.write(sep)
        file.write(str(x))
        at_start = False
    file.write(kwargs.pop("end", "\n"))
    if kwargs.pop("flush", False):
        file.flush()
 
 
if sys.version_info[0] < 3:
    sys.stdin, sys.stdout = FastIO(sys.stdin), FastIO(sys.stdout)
else:
    sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
 
input = lambda: sys.stdin.readline().rstrip("\r\n")
 

 
 
if __name__ == "__main__":
    
    main()

Solution (Python):



from math import *
from copy import *
from heapq import *
from string import *				
from random import *				
from bisect import *				
from sys import stdin				
from sys import maxsize
from operator import *				
from itertools import *
from collections import Counter		
from collections import defaultdict 

'''

'''

def solve(l,n):
	zz = n - sum(l)
	if(zz < 0):
		return -1
	return n - sum(l)

N,M = list(map(int, stdin.readline().rstrip().split()))
l = list(map(int, stdin.readline().rstrip().split()))
ans = solve(l,N)
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):
import sys
input = sys.stdin.readline
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 = 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
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

n,m = LI()
a = LI()
if sum(a) <= n:
    print(n-sum(a))
else:
    print(-1)

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

Solution (Python):
def main():
    n, m = map(int, input().split())
    num_list = list(map(int, input().split()))

    sum_count = 0
    for i in range(m):
        sum_count += num_list[i]

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

if __name__ == '__main__':
    main()

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

Solution (Python):
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, gcd
from itertools import accumulate, permutations, combinations, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N, M = MAP()
A = LIST()

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

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

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

Solution (Python):
import sys
input=lambda: sys.stdin.readline().rstrip()
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):
N, M = map(int, input().split())
As = list(map(int, input().split()))

sumA = sum(As)

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

Solution (Python):
from math import sqrt,ceil








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):
def get_ints():
    return list(map(int, input().split()))

n, m = get_ints()
a = get_ints()
total = sum(a)
print(n - total if total <= n else -1)

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

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

Solution (Python):
import math,itertools,fractions,heapq,collections,bisect,sys,queue,copy

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7
dd=[(-1,0),(0,1),(1,0),(0,-1)]
ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return input()

def main():
  n,m=LI()
  l=LI()

  sm=sum(l)
  if n<sm:
    return -1
  return n-sm


print(main())

Solution (Python):

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

total = sum(A)

print (max(-1, N - total))

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

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

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

Solution (Python):
def main():
    N, M = map(int, input().split())
    *a, = map(int, input().split())

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


if __name__ == '__main__':
    main()

Solution (Python):
n,m= list(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()))
ans = N - sum(A)
print(ans if ans >= 0 else -1)

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

Solution (Python):
import sys,collections as cl,bisect as bs,math
sys.setrecursionlimit(100000)
input = sys.stdin.readline
mod = 10**9+7
Max = sys.maxsize
def l(): 
    return list(map(int,input().split()))
def m(): 
    return map(int,input().split())
def onem(): 
    return int(input())
def s(x): 
    a = []
    if len(x) == 0:
        return []
    aa = x[0]
    su = 1
    for i in range(len(x)-1):
        if aa != x[i+1]:
            a.append([aa,su])
            aa = x[i+1]
            su = 1
        else:
            su += 1
    a.append([aa,su])
    return a
def jo(x): 
    return " ".join(map(str,x))
def max2(x): 
    return max(map(max,x))
def In(x,a): 
    k = bs.bisect_left(a,x)
    if k != len(a) and a[k] ==  x:
        return True
    else:
        return False

def pow_k(x, n):
    ans = 1
    while n:
        if n % 2:
            ans *= x
        x *= x
        n >>= 1
    return ans

"""
def nibu(x,n,r):
    ll = 0
    rr = r
    while True:
        mid = (ll+rr)//2

    if rr == mid:
        return ll
    if (ここに評価入れる):
        rr = mid
    else:
        ll = mid+1
"""

n,k = m()
a = l()

po = n - sum(a)

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

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


if __name__ == '__main__':
    main()

Solution (Python):
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

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

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

Solution (Python):


import sys
sys.setrecursionlimit(300000)


def solve(N: int, M: int, A: "List[int]"):
    s = sum(A)
    ret = N - s
    if ret < 0:
        ret = -1
    print(ret)
    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

sys.setrecursionlimit(10 ** 6)
INF = float("inf")
MOD = 10 ** 9 + 7


def input():
    return sys.stdin.readline().strip()


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


if __name__ == "__main__":
    main()

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


main()

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











import sys
sys.setrecursionlimit(10**6)
input=sys.stdin.readline
from math import floor,sqrt,factorial,hypot,log 
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
from fractions import gcd
from random import randint
def ceil(a,b): return (a+b-1)//b
inf=float('inf')
mod = 10**9+7
def pprint(*A): 
    for a in A:     print(*a,sep='\n')
def INT_(n): return int(n)-1
def MI(): return map(int,input().split())
def MF(): return map(float, input().split())
def MI_(): return map(INT_,input().split())
def LI(): return list(MI())
def LI_(): return [int(x) - 1 for x in input().split()]
def LF(): return list(MF())
def LIN(n:int): return [I() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]
def LLIN_(n: int): return [LI_() for _ in range(n)]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def I(): return int(input())
def F(): return float(input())
def ST(): return input().replace('\n', '')
def main():
    N,M=MI()
    A=sum(LI())
    if(A>N):
        print(-1)
    else:
        print(N-A)

if __name__ == '__main__':
    main()

Solution (Python):
def examA():
    N = I()

    ans = 0
    print(ans)
    return

def examB():
    N, M = LI()
    A = LI()
    S = sum(A)
    if N>=S:
        ans = N-S
    else:
        ans = -1
    print(ans)
    return

def examC():
    ans = 0
    print(ans)
    return

def examD():
    ans = 0
    print(ans)
    return

def examE():
    ans = 0
    print(ans)
    return

def examF():
    ans = 0
    print(ans)
    return

import sys,bisect,itertools,heapq,math,random
from copy import deepcopy
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
def I(): return int(readline())
def LI(): return list(map(int,readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
global mod,mod2,inf,alphabet,_ep
mod = 10**9 + 7
mod2 = 998244353
inf = 10**18
_ep = 10**(-12)
alphabet = [chr(ord('a') + i) for i in range(26)]

sys.setrecursionlimit(10**7)

if __name__ == '__main__':
    examB()

"""
142
12 9 1445 0 1
asd dfg hj o o
aidn
"""

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

for i in a:
    n -= i

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

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):
N,M = map(int,input().split())
*A, = map(int,input().split())
a = sum(A)
ans = max(-1,N-a)
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())
A = list(map(int, input().split()))
ans = max(-1, N-sum(A))
print(ans)

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

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

ans = 0
for i in a:
    ans += i
print(n-ans if n>=ans else -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):
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))

n,m = inpl()
a = inpl()
su = sum(a)
if n >= su:
    print(n-su)
else:
    print(-1)

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

Solution (Python):
import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def SI(): return sys.stdin.readline()[:-1]

def main():
    n,m=MI()
    aa=LI()
    ans=n-sum(aa)
    if ans<0:print(-1)
    else:print(ans)

main()

Solution (Python):
def main():
    N, M = list(map(int, input().split()))
    A = list(map(int, input().split()))
    t = N - sum(A)

    return t if t >= 0 else -1

print(main())