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

Submission status: Accepted

Solution code:
import sys

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

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


for i in A:
  N-=i
  if N<0:
    print(-1)
    sys.exit()
    
print(N)

Submission status: Accepted

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

Submission status: Accepted

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

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

    total = sum(As)

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


if __name__ == "__main__":
    solve()

Submission status: Accepted

Solution code:
from sys import stdin
import math
import fractions

n, m = [int(x) for x in stdin.readline().rstrip().split()]
a = [int(x) for x in stdin.readline().rstrip().split()]

count = 0
for aa in a:
    count += aa

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def main():
    n, m = [int(e) for e in input().split()]
    A = [int(e) for e in input().split()]

    ans = n - sum(A)
    if ans < 0:
        ans = -1

    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys

n, m = map(int, sys.stdin.readline().split())

line = sys.stdin.readline().split()
nums = list(map(int, line))

maxi = n - sum(nums)
print(max(-1, maxi))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from sys import stdin


def main():
    input = lambda: stdin.readline()[:-1]
    N, M = map(int, input().split())
    A = map(int, input().split())

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


main()

Submission status: Accepted

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


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


main()

Submission status: Accepted

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

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

Sum = sum(int_list)


if Sum > N:
    print("-1")
else:
    print(N - Sum)

Submission status: Accepted

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

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()))
for i in range(b):
    a-=c[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()))
S = sum(A)
if n-S >= 0:
  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(ans if ans>=0 else -1)

Submission status: Accepted

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

kotae = n - ans
if kotae >= 0:
    print(kotae)
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(n - suma)
else:
    print("-1")

Submission status: Accepted

Solution code:
a=list(input().split(" "))
N=int(a[0])
M=int(a[1])

A=list(input().split(" "))
A = [int(i) for i in A]
goukei=0
for i in range(len(A)):
    goukei+=A[i]

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

Submission status: Accepted

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

Submission status: Accepted

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

sums = 0
for i in c:sums+=i
if(sums > a):print(-1)
else:print(a-sums)

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=list(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:
#!/usr/bin/python3
# -*- coding: utf-8 -*-
n, m = map(int, input().split())
a_list = list(map(int, input().split()))
if sum(a_list) > n:
    print(-1)
else:
    print(n - sum(a_list))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

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

Submission status: Accepted

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

Submission status: Accepted

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

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

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

Submission status: Accepted

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

for i in range(n):
    m = m - a[i]

if m < 0:
    m = -1

print(m)

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:
num=input().split(" ")
days=int(num[0])
homework=int(num[1])

sum=0
num=input().split(" ")
for i in range(homework):
    sum+=int(num[i])

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

total = sum(A)
ans = N-total

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

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

if ans > n:
    ans = -1
else:
    ans = n - ans

print(ans)

Submission status: Accepted

Solution code:

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

A=[int(_) for _ in input().split(" ")]


s = N - sum(A)

if s >= 0:
    ans = s
else:
    ans = -1


print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
def homework(n, al):
    for a in al:
        n -= a
    if n>=0:
        print(n)
    else:
        print(-1)

n,m = [int(i) for i in input().split()]
al = [int(i) for i in input().split()]

homework(n, al)

Submission status: Accepted

Solution code:
n,k,*a,=map(int,open(0).read().split());print(max(-1,n-sum(a)))

Submission status: Accepted

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

temp =n - sum(time)
if temp >= 0:
    print(temp)
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()))

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

Submission status: Accepted

Solution code:
li0 = list(map(int, input().split()))
li1 = list(map(int, input().split()))
d = li0[0] - sum(li1)
if d >= 0:
    print(d)
else:
    print("-1")

Submission status: Accepted

Solution code:
def mapint_inp():
    return map(int, input().split())

def intinp():
    return int(input())

N, M = mapint_inp()
A = list(mapint_inp())


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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys, re
import math
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul	# 
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd	# 最大公約数
from heapq import heappush, heappop

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

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


n, m = MAP()
a = LIST()

for x in a:
    n -= x

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N,M=map(int,input().split())#Nが日数
A=list(map(int,input().split()))#要素M個
S=sum(A)
if S>N:
  print(-1)
else:
  print(N-S)

Submission status: Accepted

Solution code:
n,m = map(int,input().split())
a = list(map(int,input().split()))
for i in range(len(a)):
  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()))
sum_ = sum(A)

ret = max( N - sum_, -1)
print(ret)

Submission status: Accepted

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

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

ans = n
for i in range(m):
    ans -= s[i]

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

Submission status: Accepted

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

Submission status: Accepted

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


total_days = 0

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

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

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 = task + A[i]
ans = N - task
if task > N:
  ans = -1
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
from math import pi
# import bisect
# from collections import deque

Ri = lambda : [int(x) for x in sys.stdin.readline().split()]
ri = lambda : sys.stdin.readline().strip()
 
def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
INF = 10 ** 18
MOD = 998244353


# for _ in range(int(ri())):
n,k  =Ri()
a = Ri()
summ = sum(a)
if summ > n : 
    print(-1)
else:
    print(n-summ)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import numpy as np
N,M = (int(x) for x in input().split())
A = [int(x) for x in input().split()]

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

Submission status: Accepted

Solution code:
# coding: utf-8
n, m = [int(x) for x in input().split()]
As = [int(x) for x in input().split()]
s = 0
for a in As:
    s += a
ans = n - s if (n - s) >= 0 else -1
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:
import sys, math

a, b = map(int, sys.stdin.readline().split())
nums = map(int, sys.stdin.readline().split())
res = a - sum(nums)
if res < 0:
    res = -1

print(res)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

totalWorkDays = sum(a)


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

Submission status: Accepted

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

Submission status: Accepted

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

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
n, m = map(int, input().split())
l = list(map(int, input().split()))
d = sum(l)
if d > n:
    print("-1")
else:
    print(n - d)

Submission status: Accepted

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

Submission status: Accepted

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

work_days = sum(a)

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

Submission status: Accepted

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

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

Submission status: Accepted

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

sm = sum(a)

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

Submission status: Accepted

Solution code:
N,M = [int(x) for x in input().split()]
a = [int(x) for x in input().split()]
wa = 0
for i in range(M):
    wa += a[i]
print(max(-1,N-wa))

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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


def solve(N: int, M: int, A: "List[int]"):
    day = 0
    for i in range(0, M):
        day += A[i]
    
    res = N - day
    if res < 0:
        print(-1)
        return
    print(res)

    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    M = int(next(tokens))  # type: int
    A = [int(next(tokens)) for _ in range(M)]  # type: "List[int]"
    solve(N, M, A)

if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#author : dokueki

import sys
INT_MAX = sys.maxsize
INT_MIN = -(sys.maxsize)
sys.setrecursionlimit(10**7)
mod = 1000000007


def IOE():
    sys.stdin = open("input.txt", "r")
    sys.stdout = open("output.txt", "w")


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


if __name__ == "__main__":
    try:
        IOE()
    except:
        pass
    main()

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

x = N-(sum(A))

print(-1 if x < 0 else x)

Submission status: Accepted

Solution code:
def main():
    d, m = tuple([int(e) for e in input().split(' ')])
    d1 = sum([int(e) for e in input().split(' ')])
    if d1 <= d:
        print(d - d1)
    else:
        print('-1')
    return 0

main()

Submission status: Accepted

Solution code:
# coding:utf-8

import sys
import math
import time
#import numpy as np
import collections
from collections import deque
from collections import Counter
import queue
import copy
import bisect
import heapq
import itertools


#sys.setrecursionlimit(10**7)
#N, Q = map(int, input().split())
#G = [list(input()) for i in range(H)]
#INF = V * 10001
#A = [int(i) for i in input().split()]
#AB = [list(map(int, input().split())) for _ in range(K)]


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

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

Submission status: Accepted

Solution code:
base = input().split()
n = int(base[0])
m = int(base[1])
hw = input().split()
hw0 = []
for i in hw:
    hw0.append(int(i))
x = sum(hw0)
if x > n:
    print(-1)
else:
    print(n-x)

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

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

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
#B - Homework
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()))

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

Submission status: Accepted

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

sumA =  sum(A)

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

Submission status: Accepted

Solution code:
def main():
    n, m = map(int, input().split())
    a = [int(i) for i in input().split()]
    a.sort(reverse=True)
    for i in range(m):
        n -= a[i]
        if n < 0:
            print(-1)
            return       
    print(n) 
main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math
n,m=list(map(int,input().split()))
a=list(map(int,input().split()))
ans=max(-1,n-sum(a))
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:
# -*- coding: utf-8 -*-
def main():
    N,M = map(int,input().split())
    A = [int(i) for i in input().split()]
    for i in A:
        N -= 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()))

hw = sum(a)

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

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

ttt = n - sum(a)

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

Submission status: Accepted

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


result = ''
for days in A:
    N = N - days
    if N < 0:
        N = -1
        break

print(N)

Submission status: Accepted

Solution code:
import sys
input = lambda: sys.stdin.readline().rstrip()
inp = sys.stdin.buffer.readline                                
def I(): return list(map(int,inp().split()))

n,m=I()
a=I()
print(max(-1,n-sum(a)))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# import numpy as np
# import math
# import copy
# from collections import deque
import sys
input = sys.stdin.readline
# sys.setrecursionlimit(10000)


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

    res = N

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

    print(res)



main()

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 s <= N :
    print(N - s)
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:
a,b = map(int,input().split())
L= list(map(int, input().split()))
sum1 =0
for i in range(b):
    sum1 += L[i]
print(a-sum1 if a-sum1 >= 0 else -1)

Submission status: Accepted

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

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

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

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  = input().split()
A = input().split()

N = int(N)
M = int(M)
S = sum([int(a) for a in A], 0)
if N >= S:
    print(N - S)
else:
    print(-1)

Submission status: Accepted

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

Submission status: Accepted

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

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

day = n - sum(a_list)

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

Submission status: Accepted

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

from pprint import pprint
import sys

sys.setrecursionlimit(10 ** 6)
input = sys.stdin.buffer.readline

n, m = map(int, input().split())
a = []
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 sum(A) <= N else -1)

Submission status: Accepted

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

total = sum(ARR)

print(max(-1,N-total))

Submission status: Accepted

Solution code:
def q2():
    days, _ = [int(i) for i in input().split(" ")]
    hw = [int(i) for i in input().split(" ")]

    play = days - sum(hw)
    if play < 0:
        play = -1
    print(play)
    
q2()

Submission status: Accepted

Solution code:
import bisect
import collections
import sys

sys.setrecursionlimit(100000)
input = sys.stdin.readline
ACMOD = 1000000007
INF = 1 << 62


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


def llmi(n):
    return [lmi() for _ in range(n)]


N, M = lmi()

A = lmi()

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