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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
readline = sys.stdin.buffer.readline
n, m = map(int, readline().split())
a = map(int, readline().split())
print(h if (h := n - sum(a)) >= 0 else -1)

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import sys, bisect, math, itertools, string, queue, copy
import numpy as np
import scipy
from collections import Counter,defaultdict,deque
from itertools import permutations, combinations
from heapq import heappop, heappush
from fractions import gcd
input = sys.stdin.readline
sys.setrecursionlimit(10**8)
mod = 10**9+7
def inp(): return int(input())
def inpm(): return map(int,input().split())
def inpl(): return list(map(int, input().split()))
def inpls(): return list(input().split())
def inplm(n): return list(int(input()) for _ in range(n))
def inplL(n): return [list(input()) for _ in range(n)]
def inplT(n): return [tuple(input()) for _ in range(n)]
def inpll(n): return [list(map(int, input().split())) for _ in range(n)]
def inplls(n): return sorted([list(map(int, input().split())) for _ in range(n)])

n,m = inpm()
a = inpl()

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

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

def main():

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

    sumA = sum(A)

    if sumA > N:
        ans = -1
    
    else:
        ans = N - sumA

    print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
m,n,*aa = map(int, open(0).read().split())
ans = m-sum(aa)
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()))
t = N - sum(A)
if t < 0:
    print(-1)
else:
    print(t)

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
# abc163_b.py
# https://atcoder.jp/contests/abc163/tasks/abc163_b

# B - Homework /
# 実行時間制限: 2 sec / メモリ制限: 1024 MB
# 配点 : 200点

# 問題文
# 高橋君の夏休みは N日間です。
# 夏休みの宿題が M個出されており、i 番目の宿題をやるには Ai日間かかります。
# 複数の宿題を同じ日にやることはできず、また、宿題をやる日には遊ぶことができません。
# 夏休み中に全ての宿題を終わらせるとき、最大何日間遊ぶことができますか？
# ただし、夏休み中に全ての宿題を終わらせることができないときは、かわりに -1 を出力してください。

# 制約
#     1≤N≤106
#     1≤M≤104
#     1≤Ai≤104

# 入力
# 入力は以下の形式で標準入力から与えられる。
# N M
# A1 ... AM

# 出力
# 高橋君が遊ぶことのできる日数、または、-1 を出力せよ。

# 入力例 1
# 41 2
# 5 6

# 出力例 1
# 30

# 例えば、最初の 5日間で 1 番目の宿題をやり、その後 30 日間遊んで、最後の 6 日間で 2 番目の宿題をやることで、30日間遊ぶことができます。

# 入力例 2
# 10 2
# 5 6

# 出力例 2
# -1

# 宿題を終わらせることができません。

# 入力例 3
# 11 2
# 5 6

# 出力例 3
# 0

# 宿題を終わらせることはできますが、遊ぶことはできません。

# 入力例 4
# 314 15
# 9 26 5 35 8 9 79 3 23 8 46 2 6 43 3

# 出力例 4
# 9


global FLAG_LOG
FLAG_LOG = False


def log(value):
    # FLAG_LOG = True
    # FLAG_LOG = False
    if FLAG_LOG:
        print(str(value))


def calculation(lines):
    # S = lines[0]
    # N = int(lines[0])
    N, M = list(map(int, lines[0].split()))
    values = list(map(int, lines[1].split()))
    # values = list(map(int, lines[2].split()))
    # values = list()
    # for i in range(N):
    #     values.append(int(lines[i]))
    # valueses = list()
    # for i in range(N):
    #     valueses.append(list(map(int, lines[i+1].split())))

    result = max(N - sum(values), -1)

    return [result]


# 引数を取得
def get_input_lines(lines_count):
    lines = list()
    for _ in range(lines_count):
        lines.append(input())
    return lines


# テストデータ
def get_testdata(pattern):
    if pattern == 1:
        lines_input = ['41 2', '5 6']
        lines_export = [30]
    if pattern == 2:
        lines_input = ['10 2', '5 6']
        lines_export = [-1]
    if pattern == 3:
        lines_input = ['11 2', '5 6']
        lines_export = [0]
    if pattern == 4:
        lines_input = ['314 15', '9 26 5 35 8 9 79 3 23 8 46 2 6 43 3']
        lines_export = [9]
    return lines_input, lines_export


# 動作モード判別
def get_mode():
    import sys
    args = sys.argv
    global FLAG_LOG
    if len(args) == 1:
        mode = 0
        FLAG_LOG = False
    else:
        mode = int(args[1])
        FLAG_LOG = True
    return mode


# 主処理
def main():
    import time
    started = time.time()
    mode = get_mode()
    if mode == 0:
        lines_input = get_input_lines(2)
    else:
        lines_input, lines_export = get_testdata(mode)

    lines_result = calculation(lines_input)

    for line_result in lines_result:
        print(line_result)

    # if mode > 0:
    #     print(f'lines_input=[{lines_input}]')
    #     print(f'lines_export=[{lines_export}]')
    #     print(f'lines_result=[{lines_result}]')
    #     if lines_result == lines_export:
    #         print('OK')
    #     else:
    #         print('NG')
    # finished = time.time()
    # duration = finished - started
    # print(f'duration=[{duration}]')


# 起動処理
if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
#k = int(input())
#s = input()
#a, b = map(int, input().split())
#l = list(map(int, input().split()))

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


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

print(n)

Submission status: Accepted

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

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

print(n)

Submission status: Accepted

Solution code:
import math
import sys
import collections
import bisect
readline = sys.stdin.readline


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


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
# Generated by https://github.com/kyuridenamida/atcoder-tools
from typing import *
import itertools
import math
import sys

INF = float('inf')


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


def main():

    sys.setrecursionlimit(10 ** 6)

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


if __name__ == '__main__':
    main()

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
I=list(map(int,input().split()))
for i in range(m):
    n-=I[i]
    if n<0:
        print("-1")
        exit()
print(n)

Submission status: Accepted

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

for i in range(m):
  n -= lst[i]
  if n < 0:
    n = -1
    break

print(n)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
a,b=map(int,input().split())
c=0
d=list(map(int,input().split()))
for i in range(b):
    a-=d[i]
if a<0:
    print(-1)
else:
    print(a)

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
N,M = map(int,input().split())
array = list(map(int,input().split()))

if not ( 1 <= N <= 10 ** 6 and 1 <= M <= 10 ** 4 ): sys.exit()
if not ( 1 <= min(array) and max(array) <= 10 ** 4 ): sys.exit()

ans = N - sum(array)

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

Submission status: Accepted

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

total = sum(An)

if total > N:
    print('-1')
else:
    print(N - total)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def line(): return [int(i) for i in input().split(" ")]
n = line()[0]
for i in line(): n -= i
print(max(-1, n))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10**7) #再帰関数の上限,10**5以上の場合python
import math
from copy import copy, deepcopy
from copy import deepcopy as dcp
from operator import itemgetter
from bisect import bisect_left, bisect, bisect_right#2分探索
#bisect_left(l,x), bisect(l,x)#aはソート済みである必要あり。aの中からx未満の要素数を返す。rightだと以下
from collections import deque, defaultdict
#deque(l), pop(), append(x), popleft(), appendleft(x)
#q.rotate(n)で → にn回ローテート
from collections import Counter#文字列を個数カウント辞書に、
#S=Counter(l),S.most_common(x),S.keys(),S.values(),S.items()
from itertools import accumulate,combinations,permutations,product#累積和
#list(accumulate(l))
from heapq import heapify,heappop,heappush
#heapify(q),heappush(q,a),heappop(q) #q=heapify(q)としないこと、返り値はNone
from functools import reduce,lru_cache#pypyでもうごく
#@lru_cache(maxsize = None)#maxsizeは保存するデータ数の最大値、2**nが最も高効率
from decimal import Decimal

def input(): 
    x=sys.stdin.readline()
    return x[:-1] if x[-1]=="\n" else x
def printe(*x):print("## ",*x,file=sys.stderr)
def printl(li): _=print(*li, sep="\n") if li else None
def argsort(s, return_sorted=False): 
    inds=sorted(range(len(s)), key=lambda k: s[k])
    if return_sorted: return inds, [s[i] for i in inds]
    return inds
def alp2num(c,cap=False): return ord(c)-97 if not cap else ord(c)-65
def num2alp(i,cap=False): return chr(i+97) if not cap else chr(i+65)
def matmat(A,B):
    K,N,M=len(B),len(A),len(B[0])
    return [[sum([(A[i][k]*B[k][j]) for k in range(K)]) for j in range(M)] for i in range(N)]
def matvec(M,v):
    N,size=len(v),len(M)
    return [sum([M[i][j]*v[j] for j in range(N)]) for i in range(size)]
def T(M):
    n,m=len(M),len(M[0])
    return [[M[j][i] for j in range(n)] for i in range(m)]
def binr(x): return bin(x)[2:]
def bitcount(x): #xは64bit整数
    x= x - ((x >> 1) & 0x5555555555555555)
    x= (x & 0x3333333333333333) + ((x >> 2) & 0x3333333333333333)
    x= (x + (x >> 4)) & 0x0f0f0f0f0f0f0f0f 
    x+= (x >> 8); x+= (x >> 16); x+= (x >> 32) 
    return x & 0x7f

def main():
    mod = 1000000007
    #w.sort(key=itemgetter(1),reverse=True)  #二個目の要素で降順並び替え

    #N = int(input())
    N, M = map(int, input().split())
    A = tuple(map(int, input().split())) #1行ベクトル
    #L = tuple(int(input()) for i in range(N)) #改行ベクトル
    #S = tuple(tuple(map(int, input().split())) for i in range(N)) #改行行列

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




if __name__ == "__main__":
    main()

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

x  = N - sum(A)

if x < 0:
    x = -1

print(x)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import math
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 numpy as np
#import math
#from decimal import *
#from numba import njit

#@njit
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)

main()

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())
l = sum(map(int,input().split()))
print(max(-1, n-l))

Submission status: Accepted

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

Submission status: Accepted

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

for i in a:
    b = b + i

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

Submission status: Accepted

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

b = 0

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

if n >= b:
    print( n - b )

if n < b:
    print( -1 )

Submission status: Accepted

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

b = sum(a)

if n >= b:
    print( n - b )

if n < b:
    print( -1 )

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
# B Homework

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

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

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

Submission status: Accepted

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

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

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

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

Submission status: Accepted

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

ans=n-sum(a_list)

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

Submission status: Accepted

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

playable_days = N - sum(A_list)

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

Submission status: Accepted

Solution code:
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


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

    ans = max(N - sum(A), -1)

    print(ans)

    return


if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

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

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

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

Submission status: Accepted

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

if 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()))
freeday = 0
needday = 0

for i in range(m):
    needday += a[i]
    if needday > n:
        freeday = -1
        break
else:
    freeday = n - needday

print(freeday)

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

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

for i in A:
    N -= i

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

print( N-S if N - S>=0 else -1)

Submission status: Accepted

Solution code:
N,_ = map(int, input().split())
z = N - eval(input().replace(*' +'))
print(z if  0 <= z else -1 )

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

a = sum(A)

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

Submission status: Accepted

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

res = n - sum(a)

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

Submission status: Accepted

Solution code:
#=input()
#=int(input())
a,b=map(int,input().split())
#=map(str,input().split())
l=list(map(int,input().split()))
x=0
for i in l:
    x += i
    
y=a-x
if y < 0:
    print(-1)
else:
    print(y)

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

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
n, m = (int(i) for i in input().split())
tot = sum(int(i) for i in input().split())

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

Submission status: Accepted

Solution code:
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


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

Submission status: Accepted

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

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

Submission status: Accepted

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

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:
        n=-1
        break
print(n)

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

Submission status: Accepted

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

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

Submission status: Accepted

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

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

Submission status: Accepted

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

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

for i in range(Day[1]):
  Day[0] = Day[0] - work[i]
  
if(Day[0] >= 0):
  print(Day[0])
elif(Day[0] < 0):
  print("-1")

Submission status: Accepted

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

hw = sum(a)

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

if b > N :
    print(-1)
elif b <= N:
    print(N-b)

Submission status: Accepted

Solution code:
N, M = [int(_) for _ in input().split()]
A = [int(_) for _ in input().split()]
print(max(N - sum(A), -1))

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

for i in a:
    s += int(i)

if int(s) <= int(n):
    print(int(n) - int(s))
else:
    print("-1")

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def main():
    n,m = map(int,input().split())
    a = [int(i) for i in input().split()]
    Sum = sum(a)
    if n<Sum:
        print('-1')
    else:
        print(n-Sum)
main()

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import numpy as np

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

arr = np.array(lists)
days = arr.sum()

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache
import sys
sys.setrecursionlimit(10000)
INF = float("inf")
YES, Yes, yes, NO, No, no = "YES", "Yes", "yes", "NO", "No", "no"
dy4, dx4 = [0, 1, 0, -1], [1, 0, -1, 0]
dy8, dx8 = [0, -1, 0, 1, 1, -1, -1, 1], [1, 0, -1, 0, 1, 1, -1, -1]


def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W


def ceil(a, b):
    return (a + b - 1) // b


def sum_of_arithmetic_progression(s, d, n):
    return n * (2 * s + (n - 1) * d) // 2


def gcd(a, b):
    if b == 0:
        return a
    return gcd(b, a % b)


def lcm(a, b):
    g = gcd(a, b)
    return a / g * b


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

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


def main():
    solve()


if __name__ == '__main__':
    main()

Submission status: Accepted

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

a = list(map(int, input().split()))
sum = 0
for i in range(len(a)):
    sum += a[i]

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

Submission status: Accepted

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

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