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



Sample input:
41 2
5 6


Sample output:
30

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
"""
import random
import functools
import copy
import bisect
import array
import re
import collections
import heapq
import fractions
import itertools
import string
import math
from operator import itemgetter as ig
from bisect import bisect_left, bisect_right, insort_left, insort_right
from itertools import permutations, combinations, product, accumulate, groupby
from heapq import heappush, heappop
from collections import deque, defaultdict, Counter
import sys
sys.setrecursionlimit(10 ** 7)
# import numpy as np

inf = 10 ** 20
INF = float("INF")
mod = 10 ** 9 + 7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = dd + [(-1, 1), (1, 1), (1, -1), (-1, -1)]
ddn9 = ddn + [(0, 0)]
'''for dx, dy in dd:
        nx = j + dx; ny = i + dy
            if 0 <= nx < w and 0 <= ny < h:'''
"""
from collections import Counter
import math
import sys
sys.setrecursionlimit(10 ** 7)


def wi(): return list(map(int, sys.stdin.readline().split()))
# WideIntPoint


def wip(): return [int(x) - 1 for x in sys.stdin.readline().split()]


def ws(): return sys.stdin.readline().split()


def si(): return int(sys.stdin.readline())  # SingleInt


def ss(): return input()


def hi(n): return [si() for _ in range(n)]


def hs(n): return [ss() for _ in range(n)]  # HeightString


def s_list(): return list(input())


def mi(n): return [wi() for _ in range(n)]  # MatrixInt


def mip(n): return [wip() for _ in range(n)]


def ms(n): return [ws() for _ in range(n)]


def num_grid(n): return [[int(i) for i in sys.stdin.readline().split()[
    0]] for _ in range(n)]  # NumberGrid


def grid(n): return [s_list() for _ in range(n)]


def gcd(a, b):
    while b:
        a, b = b, a % b
    return a


def lcm(a, b):
    """a,bの最小公倍数"""
    return a * b // gcd(a, b)


def main():
    N, M = wi()
    A = wi()
    a = sum(A)
    if a <= N:
        print(N-a)
    else:
        print(-1)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math
import fractions
import sys
import itertools
import numpy as np
from collections import Counter
import datetime
#入力:N(int:整数)
def input1():
	return int(input())

#入力:N,M(int:整数)
def input2():
	return map(int,input().split())

#入力:[n1,n2,...nk](int:整数配列)
def input_array():
	return list(map(int,input().split()))

def keta(N):
	return len(str(N))


def input_daytime(input_time):
	time,distance=input_time.split()
	t=time.split(":")
	se=str(t[-1]).split(".")
	dt1 = datetime.timedelta(hours=int(t[0]),minutes=int(t[1]),seconds=int(se[0]),milliseconds=int(se[1]))
	return dt1

def combinations(n,r):
	return list(itertools.combinations(n,r))

# r=input1()
# print(2*math.pi*r)

n,m=input2()
A=input_array()

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

Submission status: Accepted

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

Submission status: Accepted

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

result = N - sum(A)

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

Submission status: Accepted

Solution code:
# py abc163b.py
n,m = map(int,input().split())
val = sum(list(map(int,input().split())))
if val>n:
	print(-1)
else:
	print(n-val)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python
N, M = [int(str) for str in input().strip().split()]
A = [int(str) for str in input().strip().split()]

nissu = sum(A)

print(N - nissu if N >= nissu else -1)

Submission status: Accepted

Solution code:
import sys 
import math
try:
	sys.stdin = open('input.txt', 'r') 
	sys.stdout = open('output.txt', 'w')
except:
	pass
input = sys.stdin.readline
for tt in range(1):
	# r = int(input())
	n,m = map(int,input().split())
	l = list(map(int,input().split()))
	print(-1 if sum(l)>n else n-sum(l))

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
N, M = map(int, input().split())
A = list(map(int, input().split()))
print(max(N - sum(A), -1))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
import heapq, math
from itertools import zip_longest, permutations, combinations, combinations_with_replacement
from itertools import accumulate, dropwhile, takewhile, groupby
from functools import lru_cache
from copy import deepcopy

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

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

Submission status: Accepted

Solution code:
n, m = [int(elem) for elem in input().split()]
a_lst = [int(elem) for elem in input().split()]

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline

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

a_sum = sum(a)

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
N,M = map(int,input().split())
A= list(map(int,input().split()))
a=0
for i in range(M):
 a+=A[i]
print(max(N-a,-1))

Submission status: Accepted

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

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline

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

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

Submission status: Accepted

Solution code:
day,enemy=map(int,input().split())
li = list(map(int,input().split()))
Q=sum(li)
if Q>day:
    print(-1)
else:
    print(day-Q)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N,M =map(int,input().split())
H=list(map(int,input().split()))

ALLWORK =sum(H)

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

Submission status: Accepted

Solution code:
N=int(input().split()[0])
lst=list(map(int,input().split()))
s=N-sum(lst)
if s<0:
  print(-1)
else:
  print(s)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

total = sum(data)

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

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))
def resolve():
    N, M = lr()
    A = lr()
    s = sum(A)
    print(max(-1, N-s))
resolve()

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
a=input().split(" ")
n=int(a[0])
s=input().split(" ")

sum=0
for i in s:
    sum+=int(i)

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

Submission status: Accepted

Solution code:
t=1
#t=int(input())
for _ in range(t):
    m,n = map(int,input().split(' '))
    ls = list(map(int,input().split(' ')))
    tt = sum(ls)
    m = m-tt
    if(m<0):
        print(-1)
    else:
        print(m)

Submission status: Accepted

Solution code:
# B - Homework

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

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

Submission status: Accepted

Solution code:
def resolve():
    n,m=map(int,input().split())
    a=list(map(int,input().split()))
    total=0
    for i in a:
        total+=i
    if n<total:
        print(-1)
    else:
        print(n-total)
resolve()

Submission status: Accepted

Solution code:
import sys
stdin = sys.stdin
sys.setrecursionlimit(10 ** 7)

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()))
# 入力全てを整数に変換して1引いたものの配列を受け取る
def LLI(rows_number): return [LI() for _ in range(rows_number)]

n, m = LI()
a = LI()
b = n - sum(a)
print(b if b>=0 else -1)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

s=sum(a)

if n<s:
  print("-1")
else:
  print(n-s)

Submission status: Accepted

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

s = sum(A)

ans = N - s

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

Submission status: Accepted

Solution code:
import sys
import numpy as np

#n=int(sys.stdin.readline())
n,k=map(int,sys.stdin.readline().split())
a=np.array(sys.stdin.readline().split(),dtype='int64')
#a=np.array([sys.stdin.readline().split() for i in range(n)],dtype='int64')

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

Submission status: Accepted

Solution code:
n,m = (int(x) for x in input().split())
a = [int(i) for i in input().split()]
ans = 0
for i in range(m):
	ans+=a[i]

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

Submission status: Accepted

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

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

Submission status: Accepted

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

ans=n-sum(a)

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
t = list(map(int, input().strip().split()))

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

Submission status: Accepted

Solution code:
import sys
from io import StringIO
import unittest

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

class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)
    def test_入力例_1(self):
        input = """41 2
5 6"""
        output = """30"""
        self.assertIO(input, output)
    def test_入力例_2(self):
        input = """10 2
5 6"""
        output = """-1"""
        self.assertIO(input, output)
    def test_入力例_3(self):
        input = """11 2
5 6"""
        output = """0"""
        self.assertIO(input, output)
    def test_入力例_4(self):
        input = """314 15
9 26 5 35 8 9 79 3 23 8 46 2 6 43 3"""
        output = """9"""
        self.assertIO(input, output)

if __name__ == "__main__":
    # unittest.main(
    resolve()

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
a = list(map(int,input().split()))
s = 0
for x in a:
    s += x
print(max(-1,n-s))

Submission status: Accepted

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

d = N - sum(A)

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
N, M = (int(i) for i in input().split())
A = [int(x) for x in input().split()]
#A = [[int(i) for i in input().split()] for i in range(N)]

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(1000000000)
import math
from math import gcd
def lcm(a, b): return a * b // gcd(a, b)
from itertools import count, permutations, chain
from functools import lru_cache
from collections import deque, defaultdict
from pprint import pprint
ii = lambda: int(input())
mis = lambda: map(int, input().split())
lmis = lambda: list(mis())
INF = float('inf')
N1097 = 10**9 + 7

def meg(f, ok, ng):
    while abs(ok-ng)>1:
        mid = (ok+ng)//2
        if f(mid):
            ok=mid
        else:
            ng=mid
    return ok

def get_inv(n, modp):
    return pow(n, modp-2, modp)

def factorials_list(n, modp):    # 10**6
    fs = [1]
    for i in range(1, n+1):
        fs.append(fs[-1] * i % modp)
    return fs

def invs_list(n, fs, modp):     # 10**6
    invs = [get_inv(fs[-1], modp)]
    for i in range(n, 1-1, -1):
        invs.append(invs[-1] * i % modp)
    invs.reverse()
    return invs

def comb(n, k, modp):
    num = 1
    for i in range(n, n-k, -1):
        num = num * i % modp
    den = 1
    for i in range(2, k+1):
        den = den * i % modp
    return num * get_inv(den, modp) % modp

def comb_from_list(n, k, modp, fs, invs):   
    return fs[n] * invs[n-k] * invs[k] % modp

#

class UnionFindEx:
    def __init__(self, size):
        #正なら根の番号、負ならグループサイズ
        self.roots = [-1] * size
    def getRootID(self, i):
        r = self.roots[i]
        if r < 0:   #負なら根
            return i
        else:
            r = self.getRootID(r)
            self.roots[i] = r
            return r
    def getGroupSize(self, i):
        return -self.roots[self.getRootID(i)]
    def connect(self, i, j):
        r1, r2 = self.getRootID(i), self.getRootID(j)
        if r1 == r2:
            return False
        if self.getGroupSize(r1) < self.getGroupSize(r2):
            r1, r2 = r2, r1
        self.roots[r1] += self.roots[r2]    #サイズ更新
        self.roots[r2] = r1
        return True

Yes = 'Yes'
No = 'No'


def main():
    N,M=mis()
    A=lmis()
    print(max(N-sum(A), -1))



main()

Submission status: Accepted

Solution code:
import math
import fractions
import collections
import itertools
N,M=map(int,input().split())
A=list(map(int,input().split()))
s=sum(A)
print(max(N-s,-1))

Submission status: Accepted

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

for i in a:
  n -= i


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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import sys
import heapq
import re
from itertools import permutations
from bisect import bisect_left, bisect_right
from collections import Counter, deque
from math import factorial, sqrt, ceil, gcd
from functools import lru_cache, reduce
INF = 1 << 60
MOD = 1000000007
sys.setrecursionlimit(10 ** 7)

# UnionFind
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

# ダイクストラ
def dijkstra_heap(s, edge, n):
    #始点sから各頂点への最短距離
    d = [10**20] * n
    used = [True] * n #True:未確定
    d[s] = 0
    used[s] = False
    edgelist = []
    for a,b in edge[s]:
        heapq.heappush(edgelist,a*(10**6)+b)
    while len(edgelist):
        minedge = heapq.heappop(edgelist)
        #まだ使われてない頂点の中から最小の距離のものを探す
        if not used[minedge%(10**6)]:
            continue
        v = minedge%(10**6)
        d[v] = minedge//(10**6)
        used[v] = False
        for e in edge[v]:
            if used[e[1]]:
                heapq.heappush(edgelist,(e[0]+d[v])*(10**6)+e[1])
    return d

# 素因数分解
def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr

# 2数の最小公倍数
def lcm(x, y):
    return (x * y) // gcd(x, y)

# リストの要素の最小公倍数
def lcm_list(numbers):
    return reduce(lcm, numbers, 1)

# リストの要素の最大公約数
def gcd_list(numbers):
    return reduce(gcd, numbers)

# 素数判定
def is_prime(n):
    if n <= 1:
        return False
    p = 2
    while True:
        if p ** 2 > n:
            break
        if n % p == 0:
            return False
        p += 1
    return True


# limit以下の素数を列挙
def eratosthenes(limit):
    A = [i for i in range(2, limit+1)]
    P = []

    while True:
        prime = min(A)
        
        if prime > sqrt(limit):
            break
            
        P.append(prime)
            
        i = 0
        while i < len(A):
            if A[i] % prime == 0:
                A.pop(i)
                continue
            i += 1
            
    for a in A:
        P.append(a)
            
    return P

# 同じものを含む順列
def permutation_with_duplicates(L):

    if L == []:
        return [[]]

    else:
        ret = []

        # set（集合）型で重複を削除、ソート
        S = sorted(set(L))

        for i in S:

            data = L[:]
            data.remove(i)

            for j in permutation_with_duplicates(data):
                ret.append([i] + j)

        return ret


# ここから書き始める
n, m = map(int, input().split())
a = list(map(int, input().split()))
total = sum(a)
if n >= total:
    print(n - total)
else:
    print(-1)

Submission status: Accepted

Solution code:
import numpy as np

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


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


nokori = N - np.sum(a_l)


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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10000000)


def main():
    N, M = map(int, input().split())
    A = [int(c) for c in input().split()]
    import numpy as np
    sum_ = np.sum(A)
    if N - sum_ < 0:
        print(-1)
    else:
        print(N - sum_)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n,m = map(int,input().split(' '))
A=list(map(int,input().split(' ')))
ans = n-sum(A)
print(max(-1,ans))

Submission status: Accepted

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

total_homework = sum(A)

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import collections
import sys
import numpy as np
sys.setrecursionlimit(1000000000)
from heapq import heapify,heappop,heappush,heappushpop
MOD = 10**9+7
import itertools
import math

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

Submission status: Accepted

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

Submission status: Accepted

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

ans = n-sum(a)

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

Submission status: Accepted

Solution code:
# coding: utf-8
import sys

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

N, M = lr()
A = lr()
if sum(A) > N:
    print(-1); exit()
answer = N - sum(A)
print(answer)

Submission status: Accepted

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

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

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
N, M = list(map(int, input().split()))
A = sorted(list(map(int, input().split())), reverse=True)

total = sum(A)

if N < total:
    print(-1)
elif N == total:
    print(0)
else:
    print(N - total)

Submission status: Accepted

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

temp = sum(a)

if temp <= n:
  print(n-temp)
else:
  print("-1")

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
arr = list(map(int, input().split()))
ans = n - sum(arr)
if ans < 0:
    print('-1')
else:
    print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

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

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

Submission status: Accepted

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

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
from sys import stdin
N,M = [int(x) for x in stdin.readline().rstrip().split()]
A = [int(x) for x in stdin.readline().rstrip().split()]
ans = N - sum(A)
if ans < 0:
    print(-1)
else:
    print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def main():
    n, m, *a = map(int, open(0).read().split())
    b = sum(a)
    ans = -1 if n - b < 0 else n - b
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
def main():
  N, M = (int(_) for _ in input().split())
  A = [int(_) for _ in input().split()]
  s = sum(A)
  print(N - s if N - s >= 0 else -1)
  return

if __name__ == '__main__':
  main()

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

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