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 itertools
import math
import string
import collections
from collections import Counter
from collections import deque
import sys
sys.setrecursionlimit(2*10**5)
INF = 2**60


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


def nCr(n, r):
    return math.factorial(n)//(math.factorial(n-r)*math.factorial(r))


def has_duplicates2(seq):
    seen = []
    for item in seq:
        if not(item in seen):
            seen.append(item)
    return len(seq) != len(seen)


def divisor(n):
    divisor = []
    for i in range(1, n+1):
        if n % i == 0:
            divisor.append(i)
    return divisor



dx = [-1, -1, -1, 0, 0, 1, 1, 1]
dy = [-1, 0, 1, -1, 1, -1, 0, 1]
N, M = map(int, input().split())
a = readints()
sum = 0
for i in range(M):
    sum += a[i]
if N < sum:
    print(-1)
if N >= sum:
    print(N-sum)

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

Solution (Python):
import math
import sys
import collections

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





if __name__ == '__main__':
    main()

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

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

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

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

nd = sum(As)

ans = '-1' if nd>N else N-nd
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):
x,y = map(int,input().split())
li = list(map(int,input().split()))

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

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

Solution (Python):
import sys
readline = sys.stdin.buffer.readline
def even(n): return 1 if n%2==0 else 0

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

Solution (Python):

import sys


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



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

s = sum(List)

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

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

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

res = n - sum(array)
print(res if res >= 0 else -1)

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

Solution (Python):
def solve(n, m, a_list):
    res = n - sum(a_list)
    if res >= 0:
        return res
    else:
        return -1


def main():
    n, m = map(int, input().split())
    a_list = list(map(int, input().split()))
    res = solve(n, m, a_list)
    print(res)


def test():
    assert solve(41, 2, [5, 6]) == 30
    assert solve(10, 2, [5, 6]) == -1
    assert solve(11, 2, [5, 6]) == 0
    assert solve(314, 15, [9, 26, 5, 35, 8, 9, 79, 3, 23, 8, 46, 2, 6, 43, 3]) == 9


if __name__ == "__main__":
    test()
    main()

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):
input_line = input()
Line = input_line.split()
Line = [int(s) for s in Line]

N,M = Line[0],Line[1]

input_line = input()
Line = input_line.split()
Line = [int(s) for s in Line]

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

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

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

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

print(ans);

Solution (Python):
import sys
N,M=map(int, sys.stdin.readline().split())
A=map(int, sys.stdin.readline().split())
sum_A=sum(A)
if sum_A<=N:
    print N-sum_A
else:
    print -1

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

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 = map(int, input().split())
a_sum = sum([int(x) for x in input().split()])
if n < a_sum:
    print(-1)
else:
    print(n - a_sum)

Solution (Python):



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


a_sum = sum(a_list)


c = N - a_sum
if c<0:
    print(-1)
else:
    print(c)

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

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

if __name__ == "__main__":
    main()

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

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

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

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

Solution (Python):
import sys
import socket

hostnames = ['N551J', 'F551C', 'X553M']
input_file = 'b1.in'
if socket.gethostname() in hostnames:
    sys.stdin = open(input_file)


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


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


def read_str_list():
    return input().split()


def read_str():
    return input()


def solve():
    n, m = read_int_list()
    a = read_int_list()
    res = n - sum(a)
    if res < 0:
        res = -1
    return res


def main():
    res = solve()
    print(res)


if __name__ == '__main__':
    main()

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

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

Solution (Python):
import math
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())
*arr, = map(int, input().split())

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

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

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

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

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

count = 0
for i in A:
    count = count + i

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

Solution (Python):

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

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

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

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

Solution (Python):
N, M = map(int, input().split())
l = list(map(int, input().split()))
tot = sum(l)
if N - tot >= 0:
    print(N - tot)
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):
N, M = list(map(int, input().split()))
A = list(map(int, input().split()))
Answer = N
for i in range(M):
    Answer -= A[i]
if Answer < 0:
    Answer = -1
print(Answer)

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

sums = sum(lista)

ans = N - sums

if ans < 0:
    ans = -1

print(ans)

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

suma = sum(a)

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

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

Solution (Python):
from sys import stdin

[N, M] = [int(x) for x in stdin.readline().rstrip().split()]

As = [int(x) for x in stdin.readline().rstrip().split()]


shukudai_sum = sum(As)

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

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

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

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

s=0

for a in a_list:
    s+=a


if N-s <0:
    ans=-1
else:
    ans=N-s

print(ans)

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

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

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

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

asobi = n - a_sum

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

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

vals = [int(x) for x in input().split()]

t = sum(vals)

if t > line[0]:
  print(-1)
else:
  print(line[0] - t)

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

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

print(max(-1, N))

Solution (Python):



def solve(*args: str) -> str:
    n, m = map(int, args[0].split())
    A = list(map(int, args[1].split()))
    ret = max(-1, n-sum(A))

    return str(ret)


if __name__ == "__main__":
    print(solve(*(open(0).read().splitlines())))

Solution (Python):
N, M = map(int, input().split())
for x in input().split(): N -= int(x)
print(max(N, -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())
li = list(map(int,input().split()))
if n>=sum(li):
    print(n-sum(li))
else:
    print(-1)

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

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

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

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

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

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

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

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()) 
necess = list(map(int,input().split()))
min_day = 0
for i in range(M):
    min_day += necess[i]

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

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

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=list(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 = list(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

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

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

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

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

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

ans = N
for i in range(M):
    ans -= A[i]
    
if ans > -1:
    print(ans)
else:
    print(-1)

Solution (Python):
n, m = map(int, input().split())
aaa = list(map(int, input().split()))
cnt = n - sum(aaa)
print(cnt if cnt >= 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):
N, M = map(int, input().split())
array = list(map(int, input().split()))
sum = sum(array)
day = N-sum
if day >= 0:
    print(day)
else:
    print(-1)

Solution (Python):
from math import *
test = 1

for __ in range(test):
	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()))
sum = 0
for i in range(M):
    sum += A[i]

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

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

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

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

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

print(res)

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

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

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

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

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

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

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

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

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

Solution (Python):
N, M = list(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()))
if n < sum(a):
    print(-1)
else:
    print(n-sum(a))

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

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

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

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

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


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

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

if __name__ == "__main__":
    main()

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

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

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

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

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

Solution (Python):
nm = list(map(int,input().split()))
n,m = nm[0],nm[1]
a = list(map(int,input().split()))
sam = sum(a)
ans = n - sam
if ans >= 0:
    print(ans)
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())
A = list(map(int, input().split()))

ans = N - sum(A)

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

Solution (Python):
"""
Author    : co_devil Chirag Garg
Institute : JIIT
"""
from math import pi
from collections import deque
from math import factorial
from math import log, ceil
from collections import defaultdict
from math import *
from sys import stdin, stdout
import itertools
import os
import sys
import threading
from collections import deque, Counter, OrderedDict, defaultdict
from heapq import *



from fractions import Fraction

mod = 998244353


def ii(): return int(input())


def si(): return str(input())


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


def li(): return list(mi())


def fii(): return int(stdin.readline())


def fsi(): return str(stdin.readline())


def fmi(): return map(int, stdin.readline().split())


def fli(): return list(fmi())


abd = {'a': 0, 'b': 1, 'c': 2, 'd': 3, 'e': 4, 'f': 5, 'g': 6, 'h': 7, 'i': 8, 'j': 9, 'k': 10, 'l': 11, 'm': 12,
       'n': 13, 'o': 14, 'p': 15, 'q': 16, 'r': 17, 's': 18, 't': 19, 'u': 20, 'v': 21, 'w': 22, 'x': 23, 'y': 24,
       'z': 25}


def getKey(item): return item[0]


def sort2(l): return sorted(l, key=getKey)


def d2(n, m, num): return [[num for x in range(m)] for y in range(n)]


def isPowerOfTwo(x): return (x and (not (x & (x - 1))))


def decimalToBinary(n): return bin(n).replace("0b", "")


def ntl(n): return [int(i) for i in str(n)]


def powerMod(x, y, p):
    res = 1
    x %= p
    while y > 0:
        if y & 1:
            res = (res * x) % p
        y = y >> 1
        x = (x * x) % p
    return res


graph = defaultdict(list)
visited = [0] * 1000000
col = [-1] * 1000000


def bfs(d, v):
    q = []
    q.append(v)
    visited[v] = 1
    while len(q) != 0:
        x = q[0]
        q.pop(0)
        for i in d[x]:
            if visited[i] != 1:
                visited[i] = 1
                q.append(i)
        print(x)


def make_graph(e):
    d = {}
    for i in range(e):
        x, y = mi()
        if x not in d:
            d[x] = [y]
        else:
            d[x].append(y)
        if y not in d:
            d[y] = [x]
        else:
            d[y].append(x)
    return d


def gr2(n):
    d = defaultdict(list)
    for i in range(n):
        x, y = mi()
        d[x].append(y)
    return d


def connected_components(graph):
    seen = set()

    def dfs(v):
        vs = set([v])
        component = []
        while vs:
            v = vs.pop()
            seen.add(v)
            vs |= set(graph[v]) - seen
            component.append(v)
        return component

    ans = []
    for v in graph:
        if v not in seen:
            d = dfs(v)
            ans.append(d)
    return ans


def primeFactors(n):
    s = set()
    while n % 2 == 0:
        s.add(2)
        n = n // 2
    for i in range(3, int(sqrt(n)) + 1, 2):
        while n % i == 0:
            s.add(i)
            n = n // i
    if n > 2:
        s.add(n)
    return s


def find_all(a_str, sub):
    start = 0
    while True:
        start = a_str.find(sub, start)
        if start == -1:
            return
        yield start
        start += len(sub)


def SieveOfEratosthenes(n, isPrime):
    isPrime[0] = isPrime[1] = False
    for i in range(2, n):
        isPrime[i] = True
    p = 2
    while (p * p <= n):
        if (isPrime[p] == True):
            i = p * p
            while (i <= n):
                isPrime[i] = False
                i += p
        p += 1
    return isPrime


def dijkstra(edges, f, t):
    g = defaultdict(list)
    for l, r, c in edges:
        g[l].append((c, r))

    q, seen, mins = [(0, f, ())], set(), {f: 0}
    while q:
        (cost, v1, path) = heappop(q)
        if v1 not in seen:
            seen.add(v1)
            path = (v1, path)
            if v1 == t:
                return (cost, path)

            for c, v2 in g.get(v1, ()):
                if v2 in seen:
                    continue
                prev = mins.get(v2, None)
                next = cost + c
                if prev is None or next < prev:
                    mins[v2] = next
                    heappush(q, (next, v2, path))
    return float("inf")


def binsearch(a, l, r, x):
    while l <= r:
        mid = l + (r-1)//2
        if a[mid]:
            return mid
        elif a[mid] > x:
            l = mid-1
        else:
            r = mid+1
    return -1






def readTree(n):
    adj = [set() for _ in range(n)]
    for _ in range(n-1):
        u, v = map(int, input().split())
        adj[u-1].add(v-1)
        adj[v-1].add(u-1)
    return adj


def treeOrderByDepth(n, adj, root=0):
    parent = [-2] + [-1]*(n-1)
    ordered = []
    q = deque()
    q.append(root)
    depth = [0] * n
    while q:
        c = q.popleft()
        ordered.append(c)
        for a in adj[c]:
            if parent[a] == -1:
                parent[a] = c
                depth[a] = depth[c] + 1
                q.append(a)
    return (ordered, parent, depth)














n, m = mi()
l = sorted(li())
if sum(l) <= n:
    print(n-sum(l))
else:
    print(-1)

Solution (Python):
import math
N, M = map(int,input().split())
lis = list(map(int,input().split()))
s = 0
for homework in lis:
  s += homework
  
if s > N:
  print(-1)
else:
  print(N-s)

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

Solution (Python):
import sys
sys.setrecursionlimit(100000)

def ins(): return input().split()
def ii(): return int(input())
def iil(): return list(map(int, ins()))
def lin(): return list(input())
def iin(): return map(int, ins())

n, m = iin()
a = sum(iin())
print(-1 if n-a<0 else n-a)

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


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

remainder = N - sum(A)

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

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

Solution (Python):













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


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

print(ans)

Solution (Python):
[N,M] = [int(s) for s in input().rstrip().split(' ')]
L = [int(s) for s in input().rstrip().split(' ')]
S = sum(L)
if N >= S:
    print(N-S)
else:
    print("-1")

Solution (Python):
import math
N,M=map(int, input().split())
A_list = list(map(int, input().split()))
sumA=sum(A_list)
ans=N-sumA
if(ans<=-1):
  print(-1)
else:
  print(ans)

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

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

Solution (Python):
a,b=map(int,input().split())
c=input().split()
l=[]
for i in c:
  l.append(int(i))
if sum(l)>a:
  print(-1,end="")
else:
  print(a-sum(l),end="")

Solution (Python):
import math

n, m = map(int, input().split())
arr = list(map(int, input().split()))
s = sum(arr)
print(n - s if s <= n else -1)

Solution (Python):
from heapq import heappush, heappop
from itertools import permutations, accumulate, combinations
import math
import bisect
import numpy as np
from collections import defaultdict, deque
from operator import itemgetter
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 6)




def main():
    n, m = map(int, input().split())
    A = list(map(int, input().split()))
    s = sum(A)
    ans  = max(-1, n -s)
    print(ans)

if __name__ == '__main__':
    main()

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

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

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

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

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

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

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

    for w in works:
        n -= w
    print(-1) if n < 0 else print(n)



if __name__ == '__main__':
    main()

Solution (Python):
N,M = list(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 solve():
    return max(n - np.sum(a), -1)



n, m = [int(i) for i in input().split(" ")]
a = [int(i) for i in input().split(" ")]
print(solve())

Solution (Python):

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

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

for i in items:
    n-=i
if n<=-1:
    print(-1)
    exit()
print(n)

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

total = sum(A_list)
re = N - total
if re >= 0:
    print(re)
else:
    print(-1)

Solution (Python):
N,M = map(int,input().split())
amount = 0
li = list(map(int,input().split()))
for l in li:
  amount += l
if amount <= N:
  print(N-amount)
else:
  print(-1)

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

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

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

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

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

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

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()))
s=sum(a)
day=n-s
print(day if day>=0 else -1)

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

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

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

Solution (Python):


def solve():
    N,M = map(int, input().split())
    D = N - sum(map(int, input().split()))
    if D >= 0:
        return str(D)
    else:
        return '-1'

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

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

sum_a = sum(A)

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

benkyou = sum(A)

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

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

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

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

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