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:
#!/usr/bin/env python3
# vim: set fileencoding=utf-8

# pylint: disable=unused-import, invalid-name, missing-docstring, bad-continuation


"""Module docstring
"""

import functools
import heapq
import itertools
import logging
import math
import random
import string
import sys
from argparse import ArgumentParser
from collections import defaultdict, deque
from copy import deepcopy
from typing import Dict, List, Optional, Set, Tuple


def solve(values: List[str], nb: int) -> int:
    sum_v = sum(values)
    if sum_v <= nb:
        return nb - sum_v
    return -1


def do_job():
    "Do the work"
    LOG.debug("Start working")
    # N = int(input())
    N, _M = map(int, input().split())
    values = list(map(int, input().split()))
    result = solve(values, N)
    print(result)


def print_output(testcase: int, result) -> None:
    "Formats and print result"
    if result is None:
        result = -1
    print("Case #{}: {}".format(testcase + 1, result))
    # 6 digits float precision {:.6f} (6 is the default value)
    # print("Case #{}: {:f}".format(testcase + 1, result))


def configure_log(log_file: Optional[str] = None) -> None:
    "Configure the log output"
    log_formatter = logging.Formatter(
        "%(asctime)s - %(filename)s:%(lineno)d - " "%(levelname)s - %(message)s"
    )
    if log_file:
        handler = logging.FileHandler(filename=log_file)
    else:
        handler = logging.StreamHandler(sys.stdout)
    handler.setFormatter(log_formatter)
    LOG.addHandler(handler)


LOG = None
# for interactive call: do not add multiple times the handler
if not LOG:
    LOG = logging.getLogger("template")
    configure_log()


def main(argv=None):
    "Program wrapper."
    if argv is None:
        argv = sys.argv[1:]
    parser = ArgumentParser()
    parser.add_argument(
        "-v",
        "--verbose",
        dest="verbose",
        action="store_true",
        default=False,
        help="run as verbose mode",
    )
    args = parser.parse_args(argv)
    if args.verbose:
        LOG.setLevel(logging.DEBUG)
    do_job()
    return 0


if __name__ == "__main__":
    import doctest

    doctest.testmod()
    sys.exit(main())


class memoized:
    """Decorator that caches a function's return value each time it is called.
    If called later with the same arguments, the cached value is returned, and
    not re-evaluated.
    """

    def __init__(self, func):
        self.func = func
        self.cache = {}

    def __call__(self, *args):
        try:
            return self.cache[args]
        except KeyError:
            value = self.func(*args)
            self.cache[args] = value
            return value
        except TypeError:
            # uncachable -- for instance, passing a list as an argument.
            # Better to not cache than to blow up entirely.
            return self.func(*args)

    def __repr__(self):
        """Return the function's docstring."""
        return self.func.__doc__

    def __get__(self, obj, objtype):
        """Support instance methods."""
        return functools.partial(self.__call__, obj)

Submission status: Accepted

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

sumDays = sum(A)

if sumDays <= N:
  print(N-sumDays)
else:
  print('-1')

Submission status: Accepted

Solution code:
import math

N, M = map(int, input().split())
List = [int(i) for i in input().split()]
sum = sum(List)
answer = N-sum
if answer<-1:
  answer = -1
  
  
print(answer)

Submission status: Accepted

Solution code:
nums = input()
alldays = int(nums.split(' ')[0])
hwday = input().split(' ')
hwday = list(map(int,hwday))
for i in range(len(hwday)):
	alldays -= hwday[i]
if alldays >= 0:
	print(alldays)
else:
	print('-1')

Submission status: Accepted

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

work_time = sum(a)
play_time = n - work_time 

if play_time  < 0:
    play_time = -1

print(play_time)

Submission status: Accepted

Solution code:

arg1 = list(map(int, input().split()))
arg2 = list(map(int, input().split()))

N = arg1[0]

A = sum(arg2)

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N, M = [int(a) for a in input().split()]
A =[int(a) for a in input().split()]
def f():
    if sum(A)>N:return -1
    return -sum(A)+N
print(f())

Submission status: Accepted

Solution code:

def main():
    for _ in inputt(1):
        n, m = inputi()
        A = inputl()
        n -= sum(A)
        print(-1 if n < 0 else n)


# region M


# region import
# 所有import部分

from math import *
from heapq import *
from itertools import *
from functools import reduce, lru_cache, partial
from collections import Counter, defaultdict
import re, copy, operator, cmath
import sys, io, os, builtins
sys.setrecursionlimit(1000)

# endregion

# region fastio
# 快速io，能提升大量时间

BUFSIZE = 8192
class FastIO(io.IOBase):
    newlines = 0
    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = io.BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None
    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()
    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()
    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)
class IOWrapper(io.IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")
def print(*args, **kwargs):
    sys.stdout.write(kwargs.pop("split", " ").join(map(str, args)))
    sys.stdout.write(kwargs.pop("end", "\n"))
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip()
inputt = lambda t = 0: range(t) if t else range(int(input()))
inputs = lambda: input().split()
inputi = lambda: map(int, inputs())
inputl = lambda t = 0, k = inputi: map(list, (k() for _ in range(t))) if t else list(k())

# endregion

# region bisect
# 二分搜索，标准库没有函数参数

def len(a):
    if isinstance(a, range):
        return -((a.start - a.stop) // a.step)
    return builtins.len(a)
def bisect_left(a, x, key = None, lo = 0, hi = None):
    if lo < 0: lo = 0
    if hi == None: hi = len(a)
    if key == None: key = do_nothing
    while lo < hi:
        mid = (lo + hi) // 2
        if key(a[mid]) < x: lo = mid + 1
        else: hi = mid
    return lo
def bisect_right(a, x, key = None, lo = 0, hi = None):
    if lo < 0: lo = 0
    if hi == None: hi = len(a)
    if key == None: key = do_nothing
    while lo < hi:
        mid = (lo + hi) // 2
        if x < key(a[mid]): hi = mid
        else: lo = mid + 1
    return lo
def insort_left(a, x, key = None, lo = 0, hi = None):
    lo = bisect_left(a, x, key, lo, hi)
    a.insert(lo, x)
def insort_right(a, x, key = None, lo = 0, hi = None):
    lo = bisect_right(a, x, key, lo, hi)
    a.insert(lo, x)
do_nothing = lambda x: x
bisect = bisect_right
insort = insort_right
def index(a, x, default = None, key = None, lo = 0, hi = None):
    if lo < 0: lo = 0
    if hi == None: hi = len(a)
    if key == None: key = do_nothing
    i = bisect_left(a, x, key, lo, hi)
    if lo <= i < hi and key(a[i]) == x: return a[i]
    if default != None: return default
    raise ValueError
def find_lt(a, x, default = None, key = None, lo = 0, hi = None):
    if lo < 0: lo = 0
    if hi == None: hi = len(a)
    i = bisect_left(a, x, key, lo, hi)
    if lo < i <= hi: return a[i - 1]
    if default != None: return default
    raise ValueError
def find_le(a, x, default = None, key = None, lo = 0, hi = None):
    if lo < 0: lo = 0
    if hi == None: hi = len(a)
    i = bisect_right(a, x, key, lo, hi)
    if lo < i <= hi: return a[i - 1]
    if default != None: return default
    raise ValueError
def find_gt(a, x, default = None, key = None, lo = 0, hi = None):
    if lo < 0: lo = 0
    if hi == None: hi = len(a)
    i = bisect_right(a, x, key, lo, hi)
    if lo <= i < hi: return a[i]
    if default != None: return default
    raise ValueError
def find_ge(a, x, default = None, key = None, lo = 0, hi = None):
    if lo < 0: lo = 0
    if hi == None: hi = len(a)
    i = bisect_left(a, x, key, lo, hi)
    if lo <= i < hi: return a[i]
    if default != None: return default
    raise ValueError

# endregion

# region csgraph
# 稀疏矩阵 图论部分
class Tree:
    def __init__(n):
        self._n = n
        self._conn = [[] for _ in range(n)]
        self._list = [0] * n
    def connect(a, b):
        pass

# endregion

# region ntheory
# number theory 数论部分
class Sieve:
    def __init__(self):
        self._n = 6
        self._list = [2, 3, 5, 7, 11, 13]
    def extend(self, n):
        pass


sieve = Sieve()
def isprime(n):
    pass
def prime(n):
    pass
def factorint(n):
    factordict = defaultdict(int)
    for i in sieve:
        if n <= i * i:
            break
        while not n % i:
            factordict[i] += 1
            n //= i
    if n != 1:
        factordict[n] += 1
    return factordict
# endregion

# region main
# main 函数部分

if __name__ == "__main__":
    main()

# endregion


# endregion

Submission status: Accepted

Solution code:
import sys
# sys.stdin = open('input.txt')

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

Submission status: Accepted

Solution code:
N, M = [int(el) for el in input().split()]
sm = sum([int(el) for el in input().split()])
print(-1 if N < sm else N - sm)

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

sum = 0
for a in listA :
    sum = sum + a

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

Submission status: Accepted

Solution code:
def resolve():
    N, M = map(int, input().split())
    a_list = list(map(int, input().split()))
    rel = sum(a_list)
    if(rel > N):
        print("-1")
    else:
        print(N - rel)

resolve()

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

amount = 0
for i in range(M):
    amount = amount + numbers[i]

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

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 = 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:
a=input().split()
N=int(a[0])
M=int(a[1])
M_list=input().split()
Flag=True
item_list=[]
for item in M_list :
	item_list.append(int(item))
    
if N<sum(item_list):
	print('-1')
else :
	for item in item_list :
		N-=item
	print(N)

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(abs(sum(a)-n))

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-

A,B=(int(x) for x in input().split())

days_l = [int(x) for x in input().split()]
hw = sum(days_l)

if A >= hw:
    print(A - hw)
else:
    print('-1')

Submission status: Accepted

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

Submission status: Accepted

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

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

vacation = n - sum(task)
if vacation < 0:
    vacation = -1

print(vacation)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
lists = list(map(int, input().split())) #１行の入力をi[0],i[1]というように空白で分けてを取得し、iに値を入れる
a = list(map(int, input().split())) #１行の入力をi[0],i[1]というように空白で分けてを取得し、iに値を入れる

ans = sum(a)
if ans <= lists[0]:
    print(lists[0]-ans)
else:
    print(-1)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import sys


def solve(N: int, M: int, A: "List[int]"):

    a = sum(A)

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

    return


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

if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

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

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

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

print(ans)

Submission status: Accepted

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

ans = sum(a)

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

Submission status: Accepted

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

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

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

d = 0
d = N - sum(l)

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

Submission status: Accepted

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

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

homework_day = 0
for i in range(M):
    homework_day += homework[i]

if homework_day <= N :
    print(N - homework_day)
else:
    print("-1")

Submission status: Accepted

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

a = sum(A)
output = max(N - a, -1)

print(output)

Submission status: Accepted

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

    for ai in a:
        ans -= ai
        if ans < 0:
            ans = -1
            break
    
    print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

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

homework = sum(A)
ans = N - homework

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

Submission status: Accepted

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

else:
    print(-1)

Submission status: Accepted

Solution code:
import sys
from typing import Callable, NoReturn, Tuple


def main() -> NoReturn:
    scan: Callable[[], str] = sys.stdin.readline

    n, m = map(int, scan().rstrip().split())
    a: Tuple[int] = tuple(int(a_i) for a_i in scan().rstrip().split())

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

    print(playtime)


if __name__ == '__main__':
    main()

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:
# coding: utf-8
init = [int(s) for s in input().rstrip().split(' ')]
data = [int(s) for s in input().rstrip().split(' ')]

days_homework = sum(data)
left_time = init[0] - days_homework
if left_time < 0:
    print(-1)
else:
    print(left_time)

Submission status: Accepted

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


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

ans = N-need

if ans < 0:
    ans = -1

print(ans)

Submission status: Accepted

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

AmStr = input().split(' ')
Am = []
sumA = 0
for v in AmStr:
  sumA += int(v)
  Am.append(int(v))

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

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
A = list(map(int, input().split()))
flag = True
 
for i in  A:
  N = N - i
  if N < 0:
    flag = False
    break
 
if flag == True:
  print(N)
else:
  print(-1)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
NM=input()
NM=NM.split()
A=input()
A=A.split()
sum=0
for i in A:
  sum=sum+int(i)
if(sum>int(NM[0])):
    print(-1)
else:
    print(int(NM[0])-sum)

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
A = list(map(int, input().split()))
ans = N - sum(a for a in A)

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

Submission status: Accepted

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

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

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

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

Submission status: Accepted

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

Submission status: Accepted

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

G = 0

for T in A:
    G += T

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

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

Submission status: Accepted

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

Submission status: Accepted

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

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

res = n - sum(nums)

print(-1 if res < 0 else res)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
data = input().split()
N = int(data[0])
M = int(data[1])
A = list(map(int,input().split()))

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

s = sum(arr)

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()))
sum=0
for i in range(M):
  sum+=A[i]
if N-sum>=0:
  print(N-sum)
else:
  print(-1)

Submission status: Accepted

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

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

Submission status: Accepted

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

r = N - sum(A)


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

Submission status: Accepted

Solution code:
vacationDays, homeworkN  = map(int, input().split())
homeworkDays = sum(map(int, input().split()))

PlayDays = vacationDays - homeworkDays

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

Submission status: Accepted

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

if sum(a) <= n:
    print(n-sum(a))
elif sum(a) > n:
    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()))

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-

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

req = 0
for i in range(m):
  req += A[i]

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-

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

a_total = 0
for a in a_list:
  a_total += int(a)

d = n - a_total
if d < 0:
  print(-1)
else:
  print(d)

Submission status: Accepted

Solution code:
import math

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

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

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
sum_A = sum(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 n-sum(a) >= 0:
  print(n-sum(a))
else:
  print(-1)

Submission status: Accepted

Solution code:
# 初期入力
N,M = (int(x) for x in input().split())
A = list(map(int, input().split()))

#
day_syukudai = sum(A)
day_asobu = N - day_syukudai
if day_asobu <0:
    print(-1)
else:
    print(day_asobu)

Submission status: Accepted

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

a_sum = sum(a)

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

Submission status: Accepted

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

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

H=N-sum([a for a in A])
print (H if H>=0 else -1)

Submission status: Accepted

Solution code:
N,M=map(int,input().split())
A=list(map(int,input().split()))
x=0
for i in A:
    x+= i
day=0
if x<=N:
    day=N-x
    print(day)
else:
    print('-1')

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

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

Submission status: Accepted

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

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

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

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 = list(map(int, input().split()))
A = list(map(int, input().split()))
tmp = 0
for i in range(M):
  tmp += A[i]
if N >= tmp:
  print(N - tmp)
else:
  print(-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:
#import numpy as np
import math
#from fractions import gcd

def main():

    ##get int
    first_input = list(map(lambda x:int(x), input().split(" ")))
    second_input = list(map(lambda x:int(x), input().split(" ")))

    ##get float
    #first_input = list(map(lambda x:float(x), input().split(" ")))
    #second_input = list(map(lambda x:float(x), input().split(" ")))

    ##get string
    #first_input = input().split(" ")

    N = first_input[0]
    M = first_input[1]

    Nokori = N
    for a in second_input:
        Nokori = Nokori - a

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

if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
"""
@author: H_Hoshigi
"""
def main():
    N, M = map(int, input().split())
    A_list = list(map(int, input().split()))
    diff = N - sum(A_list)
    if diff >= 0:
        print(diff)
    else:
        print(-1)

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
N,M=map(int,input().split())
A=[int(x) for x in 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:
a,b=map(int,input().split())
#a,bを同時に入力するとき便利
c=list(map(int,input().split()))
d=0
for i in range (0,b):
    d=d+c[i]
if a-d>=0:
    print(a-d)
else:
    print(-1)

Submission status: Accepted

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

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

su = 0
for i in a:
  su += i

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:


n_and_m = input()

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

homeworks = input()
homeworks = homeworks.split()

do_homework = 0
for num in homeworks:
    do_homework = do_homework + int(num)

if do_homework > n:
    print(-1)

else:
    print(n - do_homework)