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:
#coding:utf-8

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

day = 0
for i in range(m):
    ai = int(a[i])
    day += ai

ans = -1
if day <= n:
    ans = n - day

print("{}".format(ans))

Submission status: Accepted

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


result = n - sum(a)

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

Submission status: Accepted

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

A =[]

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

gokei = int(sum(A))

if N - gokei < 0:
  print('-1')

else:
  print(N - gokei)

Submission status: Accepted

Solution code:
import numpy as np

NM=np.array(input().split(),dtype=np.int32)
N=NM[0]
M=NM[1]

A=np.array(input().split(),dtype=np.int32)

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

Submission status: Accepted

Solution code:
import sys
input = lambda: sys.stdin.readline().rstrip()

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
# 整数の入力
# a = int(input())
# スペース区切りの整数の入力
# 文字列の入力
# s = input()
# 出力
# print("{} {}".format(a+b+c, s))
# b, c = map(int, input().split())

N, M = map(int, input().split())
array = list(map(int, input().strip().split()))
for value in array :
  N -= value
if N < 0 :
  N = -1
print(N)

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:
def main():
  n,m = map(int, input().split())
  A = [int(x) for x in input().split()]
  for a in A:
      n = n - a
  if n >= 0:
      print(n)
  else:
      print('-1')
  
if __name__ == "__main__":
    main()
    pass

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
A = input()
A_list = A.split(sep=' ')

count = N
for i in A_list:
    N -= int(i)
if N >= 0:
    print(N)
else:
    print(-1)

Submission status: Accepted

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


for a in A:
    n -= a

if n >=0:
    print(n)
if n < 0:
    print(-1)

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N, M = input().split()
#　宿題の日数
Work = input().split()
#　宿題の合計執行日数
Worksum = 0
for n in Work:
  Worksum += int(n)
 
if int(N)-Worksum < 0:
  print(-1)
else:
  print(int(N)-Worksum)

Submission status: Accepted

Solution code:
total_day , h_w = input().split()

data = list(map(int,input().split()))
work_day = sum(data)
free = int(total_day) - work_day

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
num= map(int, input().split())
sum1=sum(num)
if sum1>N:
    print("-1")
elif sum1<N:
    C=N-sum1
    print(C)
elif sum1==N:
    print("0")

Submission status: Accepted

Solution code:
a, b = map(int, input().split()) 
A = list(map(int, input().split())) 
jikan=0
for i in range(b):
	jikan += A[i]
if jikan>a:
	print("-1")
if jikan<=a:
	print(a-jikan)

Submission status: Accepted

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

Submission status: Accepted

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

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

s = sum(l)

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

Submission status: Accepted

Solution code:
import numpy as np

N, M = map(int, input().split())
H_list = [int(x) for x in input().split()]
np_H_list = np.array(H_list)
H_days = np.sum(np_H_list)

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

else:
    print(-1)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import sys
import math
from bisect import bisect_left
from bisect import bisect_right
import collections
import copy
import heapq
from collections import defaultdict
from heapq import heappop, heappush
import itertools
input = sys.stdin.readline
from collections import defaultdict
from heapq import heappop, heappush

from decimal import *

##### リストの 二分木検索 #####
# bisect_left(lists, 3)
# bisect_right(lists, 3)

##### プライオリティキュー #####
# heapq.heapify(a) #リストaのheap化
# heapq.heappush(a,x) #heap化されたリストaに要素xを追加
# heapq.heappop(a) #heap化されたリストaから最小値を削除＆その最小値を出力

# heapq.heappush(a, -x) #最大値を取り出す時は、pushする時にマイナスにして入れよう
# heapq.heappop(a) * (-1) #取り出す時は、-1を掛けて取り出すこと

##### タプルリストのソート #####
# sorted(ans) #(a, b) -> 1st : aの昇順, 2nd : bの昇順
# sorted(SP, key=lambda x:(x[0],-x[1])) #(a, b) -> 1st : aの昇順, 2nd : bの降順
# sorted(SP, key=lambda x:(-x[0],x[1])) #(a, b) -> 1st : aの降順, 2nd : bの昇順
# sorted(SP, key=lambda x:(-x[0],-x[1])) #(a, b) -> 1st : aの降順, 2nd : bの降順

# sorted(SP, key=lambda x:(x[1])) #(a, b) -> 1st : bの昇順
# sorted(SP, key=lambda x:(-x[1])) #(a, b) -> 1st : bの降順

##### 累乗 #####
# pow(x, y, z) -> x**y % z

def inputInt(): return int(input())
def inputMap(): return map(int, input().split())
def inputList(): return list(map(int, input().split()))

inf = float('inf')
mod = 1000000007

#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-

def main():
	N,M = inputMap()
	A = inputList()

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

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

	#print(ans)

#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
# nCr mod m
# rがn/2に近いと非常に重くなる
def combination(n, r, mod=10**9+7):
    r = min(r, n-r)
    res = 1
    for i in range(r):
        res = res * (n - i) * modinv(i+1, mod) % mod
    return res

# mを法とするaの乗法的逆元
def modinv(a, mod=10**9+7):
    return pow(a, mod-2, mod)

def egcd(a, b):
    if a == 0:
        return b, 0, 1
    else:
        g, y, x = egcd(b % a, a)
        return g, x - (b // a) * y, y

# nHr mod m
# 問題によって、combination()を切り替えること
def H(n, r, mod=10**9+7):
	# comb = Combination(n+r-1, mod)
	# return comb(n+r-1, r)
    return combination(n+r-1, r, mod)

class Combination:
    """
    O(n)の前計算を1回行うことで，O(1)でnCr mod mを求められる
    n_max = 10**6のとき前処理は約950ms (PyPyなら約340ms, 10**7で約1800ms)
    使用例：
    comb = Combination(1000000)
    print(comb(5, 3))  # 10
    """
    def __init__(self, n_max, mod=10**9+7):
        self.mod = mod
        self.modinv = self.make_modinv_list(n_max)
        self.fac, self.facinv = self.make_factorial_list(n_max)

    def __call__(self, n, r):
        return self.fac[n] * self.facinv[r] % self.mod * self.facinv[n-r] % self.mod

    def make_factorial_list(self, n):
        # 階乗のリストと階乗のmod逆元のリストを返す O(n)
        # self.make_modinv_list()が先に実行されている必要がある
        fac = [1]
        facinv = [1]
        for i in range(1, n+1):
            fac.append(fac[i-1] * i % self.mod)
            facinv.append(facinv[i-1] * self.modinv[i] % self.mod)
        return fac, facinv

    def make_modinv_list(self, n):
        # 0からnまでのmod逆元のリストを返す O(n)
        modinv = [0] * (n+1)
        modinv[1] = 1
        for i in range(2, n+1):
            modinv[i] = self.mod - self.mod//i * modinv[self.mod%i] % self.mod
        return modinv

if __name__ == "__main__":
	main()

Submission status: Accepted

Solution code:
N, M, *A = map(int, open(0).read().split())
print(max(N - sum(A), -1))

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import sys
readline = sys.stdin.buffer.readline
n,m= list(map(int,readline().rstrip().split()))
arr = list(map(int,readline().rstrip().split()))
cnt =0
for i in range(m):
  cnt += arr[i]

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
A, B = map(int, input().split())
l = list(map(int, input().split()))
count = 0
for a in l:
    count += a
output = A - count
if output < 0:
    print(-1)
else:
    print(output)

Submission status: Accepted

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

ns_time = sum(a_list)

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

Submission status: Accepted

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


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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
from pprint import pprint

N, M = map(int, sys.stdin.readline().strip().split())
A = list(map(int, sys.stdin.readline().strip().split()))

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

Submission status: Accepted

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

Submission status: Accepted

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

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import numpy as np

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

suma=np.sum(A)
remain=N-suma

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
R = lambda: map(int, input().split())
n, m = R()
print(max(n - sum(R()), -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()))

SumA = sum(A)

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

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

Submission status: Accepted

Solution code:
import sys
import math
from collections import deque
MAX_INT = int(10e10)
MIN_INT = -MAX_INT
mod = 1000000007
sys.setrecursionlimit(1000000)
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

N,M = IL()
a = IL()

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
vacationDayCount, homeworkCount = map(int, input().split())
requiredDayList = list(map(int, input().split()))

playableDayCount = vacationDayCount - sum(requiredDayList)

if(playableDayCount >= 0):
    print(playableDayCount)
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 = map(int, input().split())
a = list(map(int, input().split()))
work = 0

for i in range(m):
    work += a[i]

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(300000)

def I(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LMI(): return list(map(int, sys.stdin.readline().split()))
MOD = 10 ** 9 + 7
INF = float('inf')


N, M = MI()
A = LMI()

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

Submission status: Accepted

Solution code:
nm = input()
ai = input()

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

total = 0

for i in range(m):
    total = total + int(a[i])

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
l = [list(map(int, input().split())) for i in range(2)]
if l[0][0] < sum(l[1]):
  print(-1)
else:
  print(l[0][0] - sum(l[1]))

Submission status: Accepted

Solution code:

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

Submission status: Accepted

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

if __name__ == "__main__":
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
input_1 = input()
input_2 = input()
term, work_cnt = input_1.split(' ')
works = input_2.split(' ')

play_days = int(term)
for i in range(int(work_cnt)):
  play_days -= int(works[i])

if play_days < 0:
  play_days = -1

print(play_days)

Submission status: Accepted

Solution code:
from math import pi

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

    total = sum(A)
    result = N - total

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

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

hostname = socket.gethostname()

if hostname == 'F451C':
    sys.stdin = open('b1.in')


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


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


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


def read_str():
    return input()


def main():
    N, M = read_int_list()
    A = read_int_list()
    for i in range(M):
      total = sum(A)
    res = N - total
    if res < 0:
      res = -1
    print(res)


main()

Submission status: Accepted

Solution code:
days,works = input().strip().split()
days,works = [int(days),int(works)]
#
array = list(map(int,input().strip().split()))
#
sum = 0
for i in range(works):
    sum += array[i]
days -= sum
if days >= 0:
    print(days)
else:
    print("-1")

Submission status: Accepted

Solution code:
def calc(n, l):
    p = sum(l)
    if p > n:
        return -1
    else:
        return n - p
n, m = map(int,input().split())
l = [int(x) for x in input().split()]
print(calc(n, l))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

sum = sum(list)

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

Submission status: Accepted

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

Submission status: Accepted

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

for i in range(M):
  N -= a[i]
  
if N < 0:
  print('-1')
else:
  print(N)

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:
# coding: utf-8
# Your code here!

import sys
readline = sys.stdin.readline
read = sys.stdin.read

n,m,*a = [int(i) for i in read().split()]
print(max(-1,n-sum(a)))

Submission status: Accepted

Solution code:
o=input().rstrip().split(' ')
p=input().rstrip().split(' ')
S=0;
for i in range(0,len(p)):
    S+=int(p[i])
if S>int(o[0]):
    print(-1)
else:
    print(int(o[0])-S)

Submission status: Accepted

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

Submission status: Accepted

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

res = 0
for i in range(M):
    res += P[i]

if N - res < 0:
    print('-1')
else :
    ans = N - res
    print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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


if __name__ == "__main__":
    main()

Submission status: Accepted

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

Submission status: Accepted

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

sum_A_i = sum(A_i)

result = N - sum_A_i

if result < 0:
    result = -1

print(result)

Submission status: Accepted

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

if N < sum(A):
  print(-1)
  exit()
print(N - sum(A))

Submission status: Accepted

Solution code:
n,m = list(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:
if __name__ == "__main__":
    n, m = map(int, input().split())
    al = list(map(int, input().split()))
    res = sum(al[:m])
    res = n - res
    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()))
B = sum(A)
if B > N:
    ans = -1
else:
    ans = N - B
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import numpy as np
n, m = map(int,input().split())
a = np.array(input().split(),dtype=int)
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 = list(map(int,input().split()))
l = list(map(int,input().split()))
if a - sum(l) < 0:
    print(-1)
else:
    print(a-sum(l))

Submission status: Accepted

Solution code:
N , M  = input().split()
A   = input().split()
N , M  = int(N) , int(M)
for i in range(M):
    A[i] = int(A[i])
#print(A , M , N)
for i in range(M):
    N -= A[i]
if N < -1:
    N = -1
print(N)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
NM = input().split()
A = input().split()

leftday = int(NM[0])
for Ai in(A):
    leftday = leftday - int(Ai)

if leftday >= 0:
    print(leftday)

elif leftday < 0:
    print("-1")

Submission status: Accepted

Solution code:
N,M=map(int,input().split())
Ai=list(map(int,input().split()))
a=sum(Ai)
play=N-a

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
a=[] #appendのために宣言が必要
while True:
    try:
        a.append(list(map(int,input().split())))

    except:
        break;
        #または、quit(),os.exit()をして止める。

b=a[0][1]
cnt = 0
kadai = []
s=0

while  cnt != b:
    kadai.append(a[1][cnt])
    cnt = cnt + 1

for i in kadai:
    s = s + i
    
if a[0][0]-s>=0:
    print(a[0][0]-s)
else:
    print('-1')

Submission status: Accepted

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

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

print (play)

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

Submission status: Accepted

Solution code:
def main():
    m, n = map(int, input().split())
    Sum = 0
    A = list(map(int, input().split()))
    for i in range(n):
        Sum+=A[i]
    if Sum>m:
        print(-1)
    else:
        print(m-Sum)
 
if __name__=='__main__':
    main()

Submission status: Accepted

Solution code:
import numpy as np

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

a = sum(r)
p = N - a 
if p < 0:
    p = -1

print(p)

Submission status: Accepted

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

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

a = sum(l)

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

else:
    print(-1)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math
#数値ひとつ
#I = int(input())
#数値欲しいとき
N, M = map(int, input().split())
#文字欲しいとき
#N = input()
#それをListにしたいとき
#listA = list(N)
#受け取る数が未定かつリストにしたいとき
list = list(map(int, input().split()))

sum = 0
for syukudai in list:
    sum += syukudai

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

Submission status: Accepted

Solution code:
a = input().rstrip().split(" ")
n = int(a[0])
m = int(a[1])
b = input().rstrip().split(" ")

k=0
s=0

for i in range(m):
    s += int(b[k])
    k += 1

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

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
suma = 0
a = []
a.append(input().split())

for i in range(m):
    a[0][i] = int(a[0][i])
for i in range(m):
    suma = a[0][i] + suma

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

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

Submission status: Accepted

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

ans = 0
for i in range(m):
  ans = ans + a[i]
  
if n >= ans:
  print(n - ans)
elif n < ans:
  print(-1)

Submission status: Accepted

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

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

Submission status: Accepted

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


if __name__ == "__main__":
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
line = input().rstrip().split(' ')
n = int(line[0])
m = int(line[1])

line = input().rstrip().split(' ')
for i in range(m):
    a = int(line[i])
    n -= a

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

Submission status: Accepted

Solution code:
x,y=input().split()
x=int(x)
y=int(y)
sum=0
for i  in input().split():
	sum+=int(i)

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

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
d, hw = map(int, input().split())
n = list(map(int, input().split()))
ans = d - sum(n)

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()))
total = 0
for i in a:
  total += i
if n < total:
  print(-1)
else:
  print(n - total)

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

Submission status: Accepted

Solution code:
nm = input().split(' ')

N, M = int(nm[0]), int(nm[1])

A = input().split()

A_sum = 0

for i in A:
    A_sum += int(i)

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