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 = [int(i) for i in input().split()]
a = [int(j) for j in input().split()]
if n >= sum(a):
    print(n-sum(a))
else:
    print(-1)

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
N,M = map(int, input().split())
A = list(map(int, input().split()))  # 入力のときに N を使う必要はありません
# print(A[0]) 
F=N-sum(A)
if F>=0:
    print(F)

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

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

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.sort()
if sum(a) > n:
    print(-1)
else:
    print(n - sum(a[::2]) - sum(a[1::2]))

Submission status: Accepted

Solution code:
import math
n,m = map(int,input().split())
a = list(map(float,input().split()))
ans = 0
for i in a:
    ans += math.ceil(i)
if ans <= n:
    print(n - ans)
else:
    print(-1)

Submission status: Accepted

Solution code:
NM = input()
day, num = NM.split(' ')
day, num = int(day), int(num)
assignments = input().split(' ')

for i in range(num):
    day -= int(assignments[i])

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub

# sys.setrecursionlimit(100000)
input = sys.stdin.buffer.readline
INF = 2**62-1

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


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


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input().strip()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


@mt
def slv(N, M, A):

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


def main():
    N, M = read_int_n()
    A = read_int_n()
    print(slv(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(n - sum(a))
else:
    print(-1)

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:
days, assignment = [int(x) for x in input().split()]
assign = [int(x) for x in input().split()]
as_sum = sum(assign)
if as_sum > days:
    print(-1)
else:
    print(days - as_sum)

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
*a,=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()))

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

Submission status: Accepted

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

if N-goukei<0:
    r=-1
else:r = N-goukei
print(r)

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:
#import pysnooper
#import numpy
#import os,re,sys,operator
#from collections import Counter,deque
#from operator import itemgetter,mul
#from itertools import accumulate,combinations,groupby,combinations_with_replacement,permutations
from sys import stdin,setrecursionlimit
#from bisect import bisect_left,bisect_right
#from copy import deepcopy
#import heapq
#import math
#import string
#from time import time
#from functools import lru_cache,reduce
#from math import factorial,hypot
#import sys
#from fractions import gcd
setrecursionlimit(10**6+1)
input=stdin.readline

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

Submission status: Accepted

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

# -*- coding: utf-8 -*-


from sys import stdin

import time
import numpy as np

############################################

# read data for n sequences.
temp = stdin.readline().split()
N = int(temp[0])
M = int(temp[1])

data = []
write = stdin.readline().split()
for i in range(M):
    data.append(int(write[i]))

data = np.asarray(data)
data = np.sum(data)

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

Submission status: Accepted

Solution code:
import numpy as np
N, M = map(int, input().split()) 
A = np.array(list(map(int, input().split())))
hwdays = A.sum()
if N >= hwdays:
    print(int(N-hwdays))
else:
    print(-1)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

total = sum(a)

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

Submission status: Accepted

Solution code:
N, M = map(int,input().split())
Mi = list(map(int, input().split())) #宿題が期間内に終わるのか
for i in range(len(Mi)):
    N = N - Mi[i]
if N < 0:
    print(-1)
else:
    print(N)

Submission status: Accepted

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

Submission status: Accepted

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

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 N < s:
    print(-1)
else:
    print(N-s)

Submission status: Accepted

Solution code:
n,m = input().strip().split()
n,m = [int(n), int(m)]
array = list(map(int, input().strip().split()))
sumday = sum(array)
if n < sumday:
  print(-1)
else:
  print(n - sumday)

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

Submission status: Accepted

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

Submission status: Accepted

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

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

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

Submission status: Accepted

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

day = n

for b in a:
    day = day - b

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

Submission status: Accepted

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

Submission status: Accepted

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

a=0

for i in range(0,m):
    a+=A[i]
    
if a>n:
    print("-1")
else:
    print (n-a)

Submission status: Accepted

Solution code:
N,M = map(int, input().split())
A = input().split()
asum = 0
for i in A:
  asum += int(i)

print(max(N-asum, -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_n = list(map(int ,input().split()))

A_n.reverse()
ans=N
for i in range(M):
    ans -= A_n[i]
    
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 sum(a) > n: print(-1)
else: print(n - sum(a))

Submission status: Accepted

Solution code:
s = [input() for i in range(2)]
l1=s[0].split(" ")
l2=s[1].split(" ")

d=int(l1[0])
h_c=0
for h in l2:
  h_c+=int(h)
  
if h_c > d:
  print(-1)
else:
  print(d-h_c)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
#--Homework

N, M = map(int, input().split())
day = [int(i) for i in input().split()]

sumday = 0
for j in  range(M):
  sumday = sumday + day[j]

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
"""
NTC here
"""
 

#!/usr/bin/env python
import os
import sys
from io import BytesIO, IOBase

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

def main():
    T = 1
    while T:
        T-=1
        n, m = lin()
        a = lin()
        sm = sum(a)
        print(max(-1, n-sm))

        
        








# region fastio

BUFSIZE = 8192


class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)


class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")


sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")

# endregion

if __name__ == "__main__":
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N,M=map(int,input().split())
TaskList=list(map(int,input().split()))
    
res=0
for i in TaskList:
    res+=int(i)

if N-res>=0:
    print(N-res)

else:
    print(-1)

Submission status: Accepted

Solution code:
N, M = (int(x) for x in input().split())
A = (int(y) for y in input().split())

Sum = 0

for B in A: 
	Sum=Sum+B

if N<Sum: 
	Re=-1
else:
	Re = N - Sum
    
print(Re)

Submission status: Accepted

Solution code:
val = list(map(int, input().split(" ")))
data = list(map(int, input().split(" ")))

if sum(data) > val[0]:
    print(-1)
else:
    print(val[0] - sum(data))

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]

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

Submission status: Accepted

Solution code:
import math
def main():
    N, M = map(int, input().split())
    l = [int(_) for _ in input().split()]
    summer_vacation_day_count = sum(l)
    if summer_vacation_day_count <= N:
        out = N - summer_vacation_day_count
    else:
        out = -1
    print(out)
main()

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
a=[int(x) for x in 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 = list(map(int, input().split()))
A = sum(A)
ans = n-A
if ans<0:
  ans = -1

print(ans)

Submission status: Accepted

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

a = sum(AS)

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

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

Submission status: Accepted

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

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

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

Submission status: Accepted

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

sum=0
for i in range(len(task)):
  sum=sum+task[i]

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

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

Submission status: Accepted

Solution code:
def read():
    N, M = map(int, input().split())
    A = map(int, input().split())
    return N, M, A

def solve(N, M, A):
    x = N - sum(A)
    return x if x >= 0 else -1
    

if __name__ == '__main__':
    inputs = read()
    print("{}".format(solve(*inputs)))

Submission status: Accepted

Solution code:
days, num = input().split()
works = input().split()

days = int(days)
for i in works:
  days -= int(i)
if days < 0:
  print('-1')
else:
  print(days)

Submission status: Accepted

Solution code:
N,M=map(int,input().split())
lis=list(map(int, input().split()))
s=0
for i in lis:
    s+=i
if N-s<0:
    print("-1")
else:
    print(N-s)

Submission status: Accepted

Solution code:

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

S = sum(arr)
N = int(n)

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

else:
  	print(N-S)

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

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

for m in range(M):
    sum = sum + A[m]

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys
#sys.setrecursionlimit(150000)


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


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools
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:
n, m = map(int, input().split())
a = list(map(int, input().split()))
f = n - sum(a)
if f >= 0:
	print(f)
else:
	print(-1)

Submission status: Accepted

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

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

Submission status: Accepted

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

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

need_day = sum(A)

if N < need_day:
    print(-1)
else:
    print(N-need_day)

Submission status: Accepted

Solution code:
all_days, hw_num = map(int, input().split())
work = 0

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

for hw_day in hw_days:
    work += hw_day

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

Submission status: Accepted

Solution code:
N,M=input().split()
N=int(N)
M=int(M)
A=[int(x) for x in input().split()]
i=0
sum_A=0
result=0
if (1<=N<=10**6)and(1<=M<=10**4):
    for i in range(0,M):
        if 1<=A[i]<=10**4:
            sum_A+=A[i]
            i+=1
    result=N-sum_A
    if result<0:
        print(-1)
    else:
        print(result)

Submission status: Accepted

Solution code:
input_line=input().split()
days=int(input_line[0])
home_kinds=int(input_line[1])
required_days=input().split()
total_homework=0

for i in range(home_kinds):
    total_homework=total_homework+int(required_days[i])

if days >=total_homework:
    print(days-total_homework)
else:
    print(-1)

Submission status: Accepted

Solution code:
value = input().split(' ')
vacation = int(value[0])
homework = int(value[1])
daysInt = []

daysStr = input().split(' ')
for i in range(0, homework):
    daysInt.append(int(daysStr[i]))

sumDays = sum(daysInt)

if sumDays > vacation:
    print('-1')
else:
    print(vacation-sumDays)

Submission status: Accepted

Solution code:
i = list(map(int, input().split()))
j = list(map(int, input().split()))
a = 0
for cc in j:
  if 1 <= cc and cc <= 10**4:
    a += 1
    
if i[1] == a:
  if 1 <= i[0] and i[0] <= 10**6 and 1 <= i[1] and i[1] <= 10**4:
    if i[0] >= sum(j):
      print(i[0] - sum(j))
    else:
      print('-1')

Submission status: Accepted

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

task_days = sum(A)

if N < task_days:
    print(-1)
else:
    print(N - task_days)

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

Submission status: Accepted

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

    
playday = N - sum(A)

if playday <0:
    playday = -1
    

print(playday)

Submission status: Accepted

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

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

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

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


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

Submission status: Accepted

Solution code:
days, dummy= map(int, input().split())
list_hours = input().split()

i=0
for el in list_hours:
    list_hours[i]=int(el)
    i+=1

if(days-sum(list_hours)<0):
    print(-1)
else:
    print(days-sum(list_hours))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n,m = map(int,input().split())
lst = list(map(int,input().split()))
syukudai = 0
while lst:
    syukudai += lst.pop()

nokori = n - syukudai
if nokori < 0:
    print("-1")
else:
    print(nokori)
# print(n,m,lst)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
N, _ = input().split(" ")
N = int(N)

homeworks= input().split(" ")
homeworks = [int(homework) for homework in homeworks]
sum_homework = sum(homeworks)

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

Submission status: Accepted

Solution code:


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

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

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

    return

if __name__ == "__main__":
    main()

Submission status: Accepted

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

diff = n - sum(l)
if diff < 0:
    print(-1)
else:
    print(diff)

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
a=tuple(map(int,input().split()))
for d in a:
    n -= d
    if n < 0:
        print(-1)
        exit()
print(n)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
input1 = input().split(" ")
n = int(input1[0])
m = int(input1[1])
assignlist = input().split(" ")
con1 = n>=1 and n<=1000000
con2 = m>=1 and m<=1000000
numassign = 0
holiday = 0
if con1 == True and con2 == True:
    for i in assignlist:
        i = int(i)
        if i >= 1 and i <= 10000:
            numassign = numassign + i
        else:
            numassign = numassign
    holiday = n - numassign
    if holiday >= 0:
        print(holiday)
    else:
        print(-1)
else:
    print()

Submission status: Accepted

Solution code:
nm = list(map(int, input().split()))
am = list(map(int, input().split()))
x = 0
for i in range(len(am)):
    x += am[i]
if x > nm[0]:
    print('-1')
else:
    ans = nm[0] - x
    print(ans)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
# coding: utf-8

# def debug(arg):
#     if __debug__:
#         pass
#     else:
#         import sys
#         print(arg, file=sys.stderr)

def main():
    N, M, *A = map(int, open(0).read().split())

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


if __name__ == "__main__":
    main()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from math import floor,ceil,sqrt,factorial,log
from collections import Counter, deque
from functools import reduce
import numpy as np
def S(): return input()
def I(): return int(input())
def MS(): return map(str,input().split())
def MI(): return map(int,input().split())
def FLI(): return [int(i) for i in input().split()]
def LS(): return list(MS())
def LI(): return list(MI())
def LLS(): return [list(map(str, l.split() )) for l in input()]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def LLSN(n: int): return [LS() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]

n,m = MI()

A = LI()

sum = np.sum(A)

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

Submission status: Accepted

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

nsum=sum(alist)
if n >= nsum:
    print(n-nsum)
else:
    print("-1")

Submission status: Accepted

Solution code:
from math import gcd
from functools import reduce
from itertools import product

def resolve():
  K, M = map(int, input().split(" "))
  A = [int(x) for x in input().split(" ")]
  print(K-sum(A) if K-sum(A) >= 0 else -1)

if __name__ == "__main__":
    resolve()

Submission status: Accepted

Solution code:
n,m = map(int,input().split())
try:
  a = list(map(int,input().split()))
  b = int(sum(a))
except EOFError:
  pass
if int(n-b)<0:
  print('-1')
else:
  print(int(n-b))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
a,b=map(int,input().split())
li=input().split()

for i in range(len(li)):
  a -= int(li[i])
if a > -1:
  print(a)
else:
  print(-1)

Submission status: Accepted

Solution code:
str = input().split()
line = input().split()

num = 0
for i in range(int(str[1])):
    num = num + int(line[i])

if (int(str[0]) - num)  >= 0:
    print(int(str[0]) - num)
else:
    print(-1)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
day, task = map(int, input().split())
task_list = list(map(int, input().split()))
days = day - sum(task_list)
if days >= 0:
  print(days)
else:
  print('-1')

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#スペース区切りの整数の入力
N,M = map(int, input().split())
#スペース区切りの整数の入力リスト
A_list = list(map(int, input().split()))

sum_ = 0
for i in range(len(A_list)):
  sum_ = sum_ + A_list[i]
  
  
ans = N - sum_
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()))

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
N, M = map(int, input().split())
As = list(map(int, input().split()))
k = N - sum(As)
if k < 0:
    k = -1
print(k)

Submission status: Accepted

Solution code:
N,M=map(int,input().split())
A=input().split()
L=list(A)
no=0
for i in range(M):
  l=L[i]
  ll=int(l)
  no+=ll

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