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 = map(int, input().split())
a = list(map(int, input().split()))
ans = 0
for num in a:
    ans += num
if n - ans >= 0:
    print(n-ans)
else:
    print(-1)

Submission status: Accepted

Solution code:
import sys
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)
        sys.exit()
print(n)

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math
def fact(n):
    ans = 1
    for i in range(2, n+1):
        ans*= i
    return ans
def comb(n, c):
    return fact(n)//(fact(n-c)*c)

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

arr=[int(i)for i in input().split()]
s=sum(arr)
if s>n:
  print(-1)
elif s==n:
  print(0)
else:
  print(n-s)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
n, m, *a = map(int, open(0).read().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()))
print(n - sum(a) if n >= sum(a) else -1)

Submission status: Accepted

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

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N,M = map(int,input().split())
for Ai in input().split():
  i = int(Ai)
  N = N - i
  if N < -1:
    N = -1
    break
print(N)

Submission status: Accepted

Solution code:
n,m = input().split()
add = 0
n = int(n)
m = int(m)
lst = list(map(int,input().split()))
for i in lst:
  add += i
if add>n :
  print(-1)
elif(add == n):
  print(0)
else:
  print(n-add)

Submission status: Accepted

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

ans = n - sum(a)

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
a,b = map(int,input().split())
li = list(map(int,input().split()))
sum = 0
for i in li:
    sum += i

result = a - sum
if result < 0:
    print("-1")
else:
    print(result)

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:
def main():
    n, m = map(int, input().split())
    a = list(map(int, input().split()))
    for i in a:
        n -= i
    print(n) if n > -1 else print(-1)


if __name__=="__main__":
    main()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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


if __name__ == '__main__':
    solve()

Submission status: Accepted

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

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

Submission status: Accepted

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

s=0
c=0

for i in range(len(a)):
    s=s+a[i]

c=n-s
if c<0:
    print(-1)
else:
    print(c)

Submission status: Accepted

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

flag=0

for i in range(M):
  N-=A[i]
  if N<0:
    flag=1
    break

if flag==1:
  print(-1)
else:
  print(N)

Submission status: Accepted

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

Submission status: Accepted

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

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

if __name__ == '__main__':
    main()

Submission status: Accepted

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

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

for i in A:
  N -= i
if N < 0:
  print(-1)
else:
  print(N)

Submission status: Accepted

Solution code:
N,M=map(int,input().split())
a=input().split()
A=[]
for _ in a:
    A.append(int(_))
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()))

for i in a:
  n-=i
  if n < 0:
    print(-1)
    exit()
print(n)

Submission status: Accepted

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

sum = 0
for i in kadai:
  sum += i

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

Submission status: Accepted

Solution code:
N,M = map(int, input().split())
A = map(int, input().split())
Z = sum(A)
if (N) >= (Z):
    print((N)-(Z))
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 a:
    s+=i
    if s > n :
        print(-1)
        break
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)<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()))

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

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
x, y = map(int, input().split())
array = list(map(int, input().split()))
su = sum(array)
a = x - su
if a > -1:
    print(a)
else:
    print(-1)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

if sum(k) > int(n):
    print("-1")
    exit()

kekka = int(n) - sum(k)

print(kekka)

Submission status: Accepted

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

Su=sum(A)

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

Submission status: Accepted

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

a = [int(x) for x in input().split()]
ans = max(-1, n - sum(a))

print(ans)

Submission status: Accepted

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




main()

Submission status: Accepted

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

Submission status: Accepted

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

day = sum(A)

if m < day:
    print(-1)
else:
    print(m-day)

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

Submission status: Accepted

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

ret = -1
sum_a = sum(a)
if sum_a <= n:
    ret = n - sum_a

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

Submission status: Accepted

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

syukudai = sum(list(map(int, input().split())))
if N-syukudai < 0:
    print("-1")
else:
    print(N-syukudai)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
a, b = map(int, input().split()) 
A = list(map(int, input().split()))
gokei = sum(A)


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

Submission status: Accepted

Solution code:
def actual(n, m, a_list):
    left_days = n - sum(a_list)

    if left_days < 0:
        return -1

    return left_days


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

print(actual(n, m, a_list))

Submission status: Accepted

Solution code:
n_m = input().rstrip().split(' ')

n = int(n_m[0])
m = int(n_m[1])

a_i = input().rstrip().split(' ')
a_i_list = [int(i) for i in a_i[:m]]

finish_day = sum(a_i_list)

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

Submission status: Accepted

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

Submission status: Accepted

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

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


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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

ans = N - sum(A)
print(max(ans,-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 = sum([int(i) for i in input().split()])
if N >= A:
  print(N-A)
else:
  print(-1)

Submission status: Accepted

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

import fractions
import copy
import bisect
import math
import numpy as np
import itertools
from itertools import combinations_with_replacement
#import math#数学的計算はこれでいける。普通に0.5乗しても計算可能
#w=input()
from operator import itemgetter
from sys import stdin
#input = sys.stdin.readline#こっちの方が入力が早いが使える時に使っていこう
from operator import mul
from functools import reduce
from collections import Counter
#from collections import deque

#input = stdin.readline


j=0
k=0
n=3
r=1
a=[0]
#n=int(input())
#r=int(input())
#print(M)
#A=int(input())
#B=int(input())
#print(N)
"1行1つの整数を入力を取得し、整数と取得する"


#number_list=list(map(int, input().split(" ")))#数字の時
#print(number_list)
"12 21 332 とか入力する時に使う"
"1行に複数の整数の入力を取得し、整数として扱う"

'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
#メモ
for i in number_list:#こっちの方がrage使うより早いらしい
    print(number_list[i-1])#

'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

'''
x=[]
y=[]
for i in range(N):
    x1, y1=[int(i) for i in input().split()]
    x.append(x1)
    y.append(y1)
print(x)
print(y)
"複数行に2数値を入力する形式 x座標とy座標を入力するイメージ"
'''

'''
mixlist=[]
for i in range(N):
    a,b=input().split()
    mixlist.append((int(a),b))
print(mixlist)
"複数行にintとstrを複合して入力するやつ，今回はリスト一つで処理している"
'''

'''
#array=[input().split()for i in range(N)]
#print(type(array[0][0]))
#print(array)
"正方行列にstr型の値を入力"
'''

#brray=[list(map(int, input().split(" ")))for i in range(N)]
#print(type(brray[0][0]))
#print(brray)
'''
入力
1 2
4 5
7 8
出力結果
[[1, 2], [4, 5], [7, 8]]
'''
"列数に関して自由度の高いint型の値を入力するタイプの行列"
#以下に別解を記載
#N, M = [int(i) for i in input().split()]
'''
table = [[int(i) for i in input().split()] for m in range(m)]

print(type(N))
print(N)
print(type(M))
print(M)

print(type(table))
print(table)
'''




#s=input()
#a=[int(i) for i in s]
#print(a[0])
#print([a])
#単数値．桁ごとに分割したい．入力と出力は以下の通り
#イメージとして1桁ごとにリストに値を入れているかんじ
#intを取ると文字列分解に使える
'''
入力
1234
出力
1
[[1, 2, 3, 4]]
'''




'''
word_list= input().split(" ")
print(word_list[0])
"連続文字列の入力"
"qw er ty とかの入力に使う"
"入力すると空白で区切ったところでlistの番号が与えられる"
'''



'''
A, B, C=stdin.readline().rstrip().split()#str style 何個でもいけることが多い
print(A)
"リストではなく独立したstr型を入れるなら以下のやり方でOK"
'''


#a= stdin.readline().rstrip()
#print(a.upper())
"aという変数に入っているものを大文字にして出力"


#a,b=map(int, input().split())  #int style 複数数値入力　「A B」みたいなスペース空いた入力のとき

#なんかうまく入力されるけど
#a=[[int(i) for i in 1.strip()]for 1 in sys.stdin]
#a = [[int(c) for c in l.strip()] for l in sys.stdin]]
#print(a)
#複数行の数値を入力して正方行列を作成


##############################################################################################
##############################################################################################
#under this line explains example calculation



'''
コンビネーションの組み合わせの中身を出力する形式
for i in itertools.combinations(brray, 2)
combinationsをpermutationsにすれば順列になる
今回なら(abc133B)
入力
1 2
5 5
-2 8
出力
[[1, 2], [5, 5], [-2, 8]]
もちろん一次元リストでも使えるし
何よりiもリストのように使えるので便利
'''

#nCr combination
'''
def cmb(n,r):
    #When n < r , this function isn't valid
    r= min(n-r,r)
    #print(n,r)
    if r == 0: return 1
    over = reduce(mul, range(n, n-r, -1))
    #flochart mul(n,n-1)=x
    #next     mul(x,n-2)........(n-r+1,n-r)
    #mul read a,b and returns a*b

    under = reduce(mul, range(1, r+1))
    #print(over, under)
    #reduce is applied mul(1,2)=2
    #next   mul(2,3)=6
    #next   mul(6,4)=4.........last(r!,r+1)=r+1!

    return over // under
    #// is integer divide
    #calc example 5C2
    #over=5*4*3
    #under=3*2*1
a = cmb(n, r)
#print(a)
'''

'''
import itertools
from itertools import combinations_with_replacement

combinationについて
以下の違いを意識しよう
combinations() p, r 長さrのタプル列、ソートされた順で重複なし

combinations_with_replacement() p, r 長さrのタプル列、ソートされた順で重複あり


使用例 　　　　　　　　　　　                  出力　　
combinations('ABCD', 2)　　　　　　　　　　　　AB AC AD BC BD CD
combinations_with_replacement('ABCD', 2)　　 AA AB AC AD BB BC BD CC CD DD
'''



'''
#集計
#example
#a=[2,2,2,3,4,3,1,2,1,3,1,2,1,2,2,1,2,1]
#a=Counter(a)
for i in a.most_common(n):print(i)
#most_common()メソッドは、出現回数が多い要素順にCounterオブジェクトを並び替えます。
#引数にint型の数字nを設定した場合は、出現回数が高い上位ｎ個の要素を返します。
#何も設定しなければ、コンテナ型にあるすべての要素を出現回数の順番に並び替えたタプル型オブジェクトを返します。
#out put
#(2, 8)
 #(1, 6)
#(3, 3)
#(4, 1)
'''


#二部探索(binary search)
#A = [1, 2, 3, 3, 3, 4, 4, 6, 6, 6, 6]
#print(A)
#index = bisect.bisect_left(A, 5) # 7 最も左(前)の挿入箇所が返ってきている
#A.insert(index, 5)
#print(index)
#print(A)
'''
bisect.bisect_left(a, x, lo=0, h=len(a))
引数
a: ソート済みリスト
x: 挿入したい値
lo: 探索範囲の下限
hi: 探索範囲の上限
(lo, hiはスライスと同様の指定方法)
bisect_leftはソートされたリストaに対して順序を保ったままxを挿入できる箇所を探索します。leftが示す通り、aにすでにxが存在している場合は、挿入箇所は既存のxよりも左側になります。また、lo, hiを指定することで探索範囲を絞り込むことも可能です。デフォルトはaの全体が探索対象です。
'''

'''
素数の判定
'''
def is_prime(n):
    if n == 1: return False

    for k in range(2, int(np.sqrt(n)) + 1):
        #sqrt(n)+1以上は考えて約数はないので却下
        if n % k == 0:
            return False
            #割り切れたらFalse
    return True


'''
npのmaxとmaximumの違い
xs = np.array([1, -2, 3])
np.max(xs, 0)
この出力は3となります．[1, -2, 3]と0の4つの数字のうち，最も大きい値を出力します．

一方で，[max(1, 0), max(-2, 0), max(3, 0)]を出力したい時があります．
その時は，numpyのmaximum関数を用います．

xs = np.array([1, -2, 3])
np.maximum(xs, 0)  # [1, 0, 3]

'''

def factorial(x, mod=10**9+7):
    # x!
    # 階乗
    # ex) factorial(5) = 120
    tmp = 1
    for i in range(1, x+1):
        tmp = (tmp * i) % mod
    return tmp
    '''
    Basically, when you do a**d % n, you actually have to calculate a**d, which could be quite large.
    But there are ways of computing a**d % n without having to compute a**d itself, and that is what pow does.
    '''
"#a,bの最大公約数"
def gcd(a, b):
    while b:#0以外なら進んでいくが、0になった時にとまる余りが0より、最大公約数と言える
        #print(a,b)#2,3
        #やり方てきにユークリッドの互除法か
        a, b = b, a % b#aには2 bには2%3が入る
    return a

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

"#nの約数を全て求める"
def divisor(n):
    i = 1
    table = []
    while i * i <= n:
        if n%i == 0:
            table.append(i)
            table.append(n//i)
        i += 1
    table = list(set(table))
    return table


########################################################################
########################################################################
#b2=a[:]  #1次元のときはコピーはこれで良い
#print(b2)

#a= [[0]*3 for i in range(5)] #2次元配列はこう準備、[[0]*3]*5だとだめ
#b3=copy.deepcopy(a)  #2次元配列はこうコピーする
#print(b3)

'''
ascii_letters = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'
ascii_lowercase = 'abcdefghijklmnopqrstuvwxyz'
ascii_uppercase = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
digits = '0123456789'
hexdigits = '0123456789abcdefABCDEF'
letters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuv...\xaf\xb0...
lowercase = 'abcdefghijklmnopqrstuvwxyz'
octdigits = '01234567'
printable = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTU...
punctuation = '!"#$%&\'()*+,-./:;<=>?@[\\]^_`{|}~'
uppercase = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
whitespace = '\t\n\x0b\x0c\r '
'''
'''
引数endに任意の文字列を指定すると、その文字列が改行の代わりに最後に挿入される。例えば連続するprint()の出力を改行なしで単純に連結したい場合は空文字列''を指定すればよい。

print('abc', end='---')
print('xyz')
# abc---xyz

print('abc', end='')
print('xyz')
# abcxyz
source: print_basic.py
なお、デフォルトで改行されるのは引数endのデフォルト値が改行文字'\n'に設定されているから。
'''

def main():
    n=3
    steps=0
    state=0
    w=1
    j=0
    k=0
    #lenを変数に置くと事故るから注意
    #n=int(input())
    #a,b=input().split(" ")#a,bがともに文字列のとき
    n,m=map(int, input().split(" "))

    #mapでとってもstrで変換すればappend可能
    #s=input()
    #a=[i for i in s]#int(i)にすれば数字も行ける
    al=list(map(int, input().split(" ")))#数字の時
    if n<sum(al):
        print(-1)
        sys.exit()
    print(n-sum(al))
    #print(a)
    #brray=[list(map(int, input().split(" ")))for i in range(n)]
    #print(brray)


    #for i in range(1,n+1,2):#これで1個飛ばしループになる
    # pass
     #print(i)

    l = ['aaa', 'bbb', 'ccc']
    x=l.index('aaa')#ある要素のインデックス番号を取得
    #s = ''.join(l)
    #s = " ".join(map(str,a))#スペースを空ける時はこう
    #print(s)
    # aaabbbccc

    #if state in known_states and not flag: # state => 2 steps => 5
        #こうやってある要素がリストの中にあるか探すのか
    #print(f'steps: {steps}, state: {state}')
    #こう書いてあるとデバックしやすい

    #dp= [[0]*3 for i in range(5)]#列　行
    #dp用の0の入ったやつ
    #dp= [[0]*(w+1) for i in range(n+1)]#0からwまでのw+1回計算するから
    #print(dp)＃初期条件が入る分計算回数+1列分必要(この場合は判断すべきものの数)
    DP = np.zeros(w+1, dtype=int)#これでも一次元リストが作れる
    exdp=np.zeros((3,4)) # ３×４の２次元配列を生成。2次元ならこう
    #dtypeは指定しないとfloatになる
    #for i in range(n):#ちょっとした入力に便利
    #    a, b = map(int, input().split())
        #dp[i][0] += [a]
        #これだとintとlistをつなぐことになって不適
    #    dp[i] += [a]
    #    dp[i] += [b]
        #これはうまくいく
        #やり方はいろいろあるということ
    #print(dp)


    #brray=[list(map(int, input().split(" ")))for i in range(N)
    #print(brray)



    '''
    入力
    1234
    出力
    [1, 2, 3, 4]
    '''
    pin_l=["x" for i in range(10)]#内包表記に慣れろ
    #print(pin_l)

    ls = ["a", "b", "c", "d", "e"]


    #print(ls[2:5])
    #スライスでの取得

    #print(ls[:-3])
    #一番左端から右から3番目より左まで取得

    #print(ls[:4:2])
    #スライスで1個飛ばしで取得
    #ないときは左端スタート
    #始点のインデックス番号 : 終点のインデックス番号 : スキップする数+1
    #print(ls[::2])
    '''
    lsというリストの場合に、1つ飛びの値を取得したい場合には
    ls[::2]
    のようにします。こうすると、
    ["a", "c", "d"]と出力される
    '''

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
yasumi,homework=map(int,input().split())
S=list(map(int,input().split()))

for i in range(homework):
    yasumi-=S[i]
    

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

Submission status: Accepted

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

d = sum(A)

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

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

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

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:
import numpy as np
N,M=map(int,input().split())
p=list(map(int,input().split()))
if np.sum(p)>N:
  print(-1)
else:
  print(N-np.sum(p))

Submission status: Accepted

Solution code:
import math
import numpy as np

def main():
  N,M = (int(x) for x in input().split())
  A = [int(x) for x in input().split()]
  
  for i in range(M):
    N = N - A[i]
  
  if N < 0:
    print('-1')
  else:
    print(N)  
  
if __name__ == '__main__':
  main()

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
A = list(map(int, input().split()))
# M個入力する
# Nが合計を下回ったらつまりマイナスだったら-1を出力
print(max(N - sum(A), -1))

Submission status: Accepted

Solution code:
N,M=map(int,input().split())
L=list(map(int,input().split()))
if N-sum(L)>=0:
  print(N-sum(L))
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,x = map(int,input().split())
a = list(map(int,input().split()))
sum = 0

for i in a:
    sum+=i
if sum>n:
    print(-1)
else:
    print(n-sum)

Submission status: Accepted

Solution code:
import numpy as np

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

ans = n - a.sum()

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

Submission status: Accepted

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

Submission status: Accepted

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

s = sum(a)

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

Submission status: Accepted

Solution code:
import sys
from io import StringIO
import unittest


class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)

    def test_入力例_1(self):
        input = """41 2
5 6"""
        output = """30"""
        self.assertIO(input, output)

    def test_入力例_2(self):
        input = """10 2
5 6"""
        output = """-1"""
        self.assertIO(input, output)

    def test_入力例_3(self):
        input = """11 2
5 6"""
        output = """0"""
        self.assertIO(input, output)

    def test_入力例_4(self):
        input = """314 15
9 26 5 35 8 9 79 3 23 8 46 2 6 43 3"""
        output = """9"""
        self.assertIO(input, output)


def resolve():
    n, a = read()
    result = think(n, a)
    write(result)


def read():
    n, m = read_int(2)
    return n, read_int(m)


def read_int(n):
    return read_type(int, n, sep=' ')


def read_float(n):
    return read_type(float, n, sep=' ')


def read_type(t, n, sep):
    return list(map(lambda x: t(x), read_line().split(sep)))[:n]


def read_line(n=0):
    if n == 0:
        return input().rstrip()
    else:
        return input().rstrip()[:n]


def think(n, a):
    total = sum(a)
    return -1 if n < total else n - total


def write(result):
    print(result)


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

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
A = list(map(int, input().split()))
r=N
for x in A:
    r-=x
    if r<0:
        r=-1
        break
print(r)

Submission status: Accepted

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

    for i in A:
        if i > N:
            print(-1)
            return
        ans = ans - i
        if ans < 0:
            print(-1)
            return
    print(ans)

main()

Submission status: Accepted

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

print(max(a - c, -1))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

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

Submission status: Accepted

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

for i in li:
  x = x - i

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

Submission status: Accepted

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

print("{}".format(-1 if sum(A) > N else (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(ans)
else:
    print(-1)

Submission status: Accepted

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

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