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:
from collections import deque, Counter, defaultdict
from itertools import chain, combinations
import json
# import numpy as np
import bisect
import sys
import math
import bisect
from functools import lru_cache

sys.setrecursionlimit(10 ** 8)

M = 10 ** 9 + 7
INF = 10 ** 17


def main():
    # N = int(input())
    N,M = [int(a) for a in input().split()]
    A = [int(a) for a in input().split()]
    t = sum(A)
    print(N-t if N-t>=0 else -1)

    # @lru_cache(None)
    # def f(i, j):
    #     if i < 0 or j < 0:
    #         return -INF
    #     if i == 0:
    #         return -INF
    #     if abs(j - i // 2 - 1) >= 2:
    #         return -INF
    #     if j == 0:
    #         return 0
    #     if j == 1:
    #         return max(A[:i])
    #     return max(A[i - 1] + f(i - 2, j - 1), f(i - 1, j))
    #
    # print(f(N, math.floor(N / 2)))


if __name__ == "__main__":
    main()

Submission status: Accepted

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

Submission status: Accepted

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

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 = 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:
import math

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

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

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()))
cnt = 0
for i in range(m):
    cnt += a[i]
if cnt <= n:
    print(n - cnt)
else:
    print(-1)

Submission status: Accepted

Solution code:
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
from pprint import pprint
from copy import deepcopy
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor
from operator import mul
from functools import reduce
from pprint import pprint


sys.setrecursionlimit(2147483647)
INF = 10 ** 15
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def I(): return int(sys.stdin.buffer.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 1000000007

n, m = LI()
ret = sum(LI())
if ret > n:
    print(-1)
else:
    print(n - ret)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys


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


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    M = int(next(tokens))  # type: int
    A = [int(next(tokens)) for _ in range(M)]  # type: "List[int]"
    print(solve(N, M, A))

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(-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()]
s = sum(a)

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

Submission status: Accepted

Solution code:

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

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

Submission status: Accepted

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

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

total = sum(homework)

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

Submission status: Accepted

Solution code:
N, M = map(lambda x: int(x), input().split(" "))
As =list(map(lambda x: int(x), input().split(" ")))

do_days = sum(As)

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

Submission status: Accepted

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



if __name__ == '__main__':
    solve()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#B

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

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

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

Submission status: Accepted

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

sum_a=sum(a)

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import sys, math
def input(): return sys.stdin.readline().strip()

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

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


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
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 = [int(x) for x in input().split()]
A = [int(x) for x in input().split()]

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

Submission status: Accepted

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

if ans >= 0:
    print(ans)
    exit()
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:
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,*A = map(int,open(0).read().split())

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
import itertools
if sys.platform =='ios':
    sys.stdin=open('input_file.txt')
    
n,m=map(int,input().split())

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


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

Submission status: Accepted

Solution code:
# print('input >>')
N, M = map(int,(input().split()))
As = list(map(int,(input().split())))

days = sum(As)
free_days = N - days

# print('-----output-----')
if free_days >= 0:
    print(free_days)
else:
    print(-1)

Submission status: Accepted

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

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

Submission status: Accepted

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

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
## coding: UTF-8
from decimal import *
from itertools import permutations, combinations,combinations_with_replacement,product
import math
s = input().split()
p = [int(w) for w in s] #これで勝手にNまで拾ってくれます
t = input().split()
q = [int(w) for w in t] #これで勝手にNまで拾ってくれます

ans = p[0] - sum(q)
if(ans < 0):
    ans = -1
print(ans)

Submission status: Accepted

Solution code:
def Int():
    return int(input())
def Ints():
    return map(int,input().split())
def IntList():
    return list(Ints())
def IntMat(N):
    return [IntList() for i in range(N)]

N,M = Ints()
A = IntList()

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

Submission status: Accepted

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

Submission status: Accepted

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

if __name__ == '__main__':
    main()

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

stdin = sys.stdin

ns = lambda: stdin.readline().rstrip()
ni = lambda: int(stdin.readline().rstrip())
nm = lambda: map(int, stdin.readline().split())
nl = lambda: list(map(int, stdin.readline().split()))

n,m = nm()
a = sum(nm())
print(-1 if a > n else n-a)

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
rs = lambda: input().strip()
ri = lambda: int(input())
rl = lambda: list(map(int, input().split()))
mod = 10**9 + 7

import math

N, M = rl()
A = rl()

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

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

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

Submission status: Accepted

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

ans = sum(a)

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

Submission status: Accepted

Solution code:
import sys
#import numpy as np

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

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

days = sum(A)

ans = N - days if N - days >= 0 else -1

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

asum=sum(a)

if(asum>n):
    print("-1")
else:
    print(n-asum)

Submission status: Accepted

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

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

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:
INF = 10 ** 9
import sys
sys.setrecursionlimit(100000000)
dy = (-1,0,1,0)
dx = (0,1,0,-1)
from  collections import deque

def main():
    n,m = map(int,input().split())
    a  = list(map(int,input().split()))
    x  =sum(a)
    if x > n:
        print(-1)
    else:
        print(n - x)
if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
N, K = map(int, input().split())
days = list(map(int, input().split()))

rest = N - sum(days)
print(max(rest, -1))

Submission status: Accepted

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

a = sum(A)

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

Submission status: Accepted

Solution code:
import heapq
from collections import defaultdict, deque
from math import ceil, factorial, gcd
from itertools import accumulate
import sys
import bisect
import numpy as np

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

si = lambda: input().strip()
ii = lambda: int(input())
mii = lambda: map(int, input().split())
lmii = lambda: list(map(int, input().split()))
smii = lambda: sorted(map(int, input().split()))

# ----------

N, M = mii()
A = lmii()

total = sum(A)

enjoy = N - total

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

Submission status: Accepted

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

Submission status: Accepted

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

s = sum(li)
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()))
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()))
print(max(-1, n-sum(a)))

Submission status: Accepted

Solution code:
[n,m] = [int(i) for i in input().split()]
a = [int(i) for i in 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()))
s=sum(A)
if(N-s>=0):
    print(N-s)
else:
    print(-1)

Submission status: Accepted

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

total = sum(A)
residue = n - total

if residue < 0:
    residue = -1
print(residue)

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
A = [int(x) for x in 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()))
print(max(-1, n - sum(A)))

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
hw = list(map(int, input().split()))
chk = 0
for i in hw:
    chk+=i
ans = n - chk
if ans < 0:
    print(-1)
else:
    print(ans)

Submission status: Accepted

Solution code:
# ABC163b


def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**6)
    # 再帰関数を使わない限りPypyで出すこと

    def dump(*args):
        sys.stderr.write(str(args))

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


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
from collections import deque
from heapq import heapify,heappop,heappush,heappushpop
from copy import copy,deepcopy
from itertools import permutations,combinations
from collections import defaultdict,Counter
# from math import gcd,ceil,floor,factorial
# from fractions import gcd
from functools import reduce
from pprint import pprint

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

def mylistinput(n):
    return [ list(myinput()) for _ in range(n) ]

def mycol(data,col):
    return [ row[col] for row in data ]

def mysort(data,col):
    data.sort(key=lambda x:x[col],reverse=False)
    return data

def mymax(data):
    M = -1*float("inf")
    for i in range(len(data)):
        m = max(data[i])
        M = max(M,m)
    return M

def mymin(data):
    m = float("inf")
    for i in range(len(data)):
        M = min(data[i])
        m = min(m,M)
    return m

def myoutput(ls,space=True):
    if space:
        if len(ls)==0:
            print(" ")
        elif type(ls[0])==str:
            print(" ".join(ls))
        elif type(ls[0])==int:
            print(" ".join(map(str,ls)))
        else:
            print("Output Error")
    else:
        if len(ls)==0:
            print("")
        elif type(ls[0])==str:
            print("".join(ls))
        elif type(ls[0])==int:
            print("".join(map(str,ls)))
        else:
            print("Output Error")

n,m = myinput()
a = list(myinput())

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()))
suma = 0
for a in A:
    suma += a
if suma <= N:
    print(N - suma)
else:
    print("-1")

Submission status: Accepted

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

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

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

Submission status: Accepted

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

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:
# import string
import sys
sys.setrecursionlimit(10 ** 5 + 10)
def input(): return sys.stdin.readline().strip()

def resolve():

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

resolve()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# ABC163 B

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

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

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
N,D=map(int,(input().split()))
L=list(map(int,(input().split())))
S=sum(L)
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()))
t=sum(a)
if t>n:
  print(-1)
else:
  print(n-t)

Submission status: Accepted

Solution code:
N,K = map(int,input().split())
a = list(map(int,input().split()))

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

Submission status: Accepted

Solution code:
x,y = map(int,input().split())
li = list(map(int,input().split()))

for day in li:
    x -= day

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

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)
print(ans if ans >= 0 else -1)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python3

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

if __name__ == "__main__":
    main()

Submission status: Accepted

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

homework = sum(A)

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

Submission status: Accepted

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

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

Submission status: Accepted

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

res = N - sum(A)

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

Submission status: Accepted

Solution code:
from sys import stdin
from sys import setrecursionlimit
from math import pi
setrecursionlimit(10 ** 7)

n,m = map(int,stdin.readline().rstrip().split())
a = list(map(int,stdin.readline().rstrip().split()))

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

Submission status: Accepted

Solution code:
#B
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:
import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
printV = lambda x: print(*x, sep="\n")
printH = lambda x: print(" ".join(map(str,x)))
def IS(): return sys.stdin.readline()[:-1]
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 LI1(): return list(map(int1, sys.stdin.readline().split()))
def LII(rows_number): return [II() for _ in range(rows_number)]
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def LLI1(rows_number): return [LI1() for _ in range(rows_number)]
mo = 10**9+7

def main():
	n,m = MI()
	a = LI()
	tot = sum(a)
	if tot > n:
		print(-1)
	else:
		print(n-tot)

if __name__ == '__main__':
	main()

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:

import sys
sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline

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:
import sys

def solve():
    input = sys.stdin.readline
    N, M = map(int, input().split())
    A = [int(a) for a in input().split()]
    if N < sum(A): print(-1)
    else: print(N - sum(A))

    return 0

if __name__ == "__main__":
    solve()

Submission status: Accepted

Solution code:
import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines

def main():
    N,M = map(int, readline().split())
    A = [int(i) for i in readline().split()]

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


if __name__ == "__main__":
    main()

Submission status: Accepted

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

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
l=list(map(int,input().split()))
ans=n
for i in l:
  ans-=i
  if ans<0:
    ans=-1
    break
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 -1)

Submission status: Accepted

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

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

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
sys.setrecursionlimit(10**6)
from math import floor,ceil,sqrt,factorial,log,pi
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 operator import itemgetter
from fractions import gcd
mod = 10 ** 9 + 7
inf = float('inf')
ninf = -float('inf')
 
#整数input
def ii(): return int(sys.stdin.readline().rstrip()) #int(input())
def mii(): return map(int,sys.stdin.readline().rstrip().split())
def limii(): return list(mii()) #list(map(int,input().split()))
def lin(n:int): return [ii() for _ in range(n)]
def llint(n: int): return [limii() for _ in range(n)]
#文字列input
def ss(): return sys.stdin.readline().rstrip() #input()
def mss(): return sys.stdin.readline().rstrip().split()
def limss(): return list(mss()) #list(input().split())
def lst(n:int): return [ss() for _ in range(n)]
def llstr(n: int): return [limss() for _ in range(n)]

#本当に貪欲法か？ DP法では？？
#本当に貪欲法か？ DP法では？？
#本当に貪欲法か？ DP法では？？


n,m=mii()
arr=limii()

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

Submission status: Accepted

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

a_sum = sum(a)

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

Submission status: Accepted

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

Submission status: Accepted

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

s = list(map(int, input().split()))
ans = n - sum(s)
print( ans if ans >= 0 else -1)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

cnt =0
for i in range(m):
    cnt+=a[i]
ans = n-cnt
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()))
tmp=N-sum(A)
if tmp>=0:
    print(tmp)
else:
    print(-1)

Submission status: Accepted

Solution code:
import math
def main():

    N, M = map(int, input().split())
    A = list(map(int, input().split()))
    v = sum(A)
    if v <= N: return N-v
    return -1

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