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

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

Submission status: Accepted

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

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

Submission status: Accepted

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


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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10 ** 6)
# input = sys.stdin.readline    ####
int1 = lambda x: int(x) - 1
def II(): return int(input())

def MI(): return map(int, input().split())
def MI1(): return map(int1, input().split())

def LI(): return list(map(int, input().split()))
def LI1(): return list(map(int1, input().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]

INF = float('inf')

def solve():
    n, m = MI()
    A = LI()

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


if __name__ == '__main__':
    solve()

Submission status: Accepted

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

sum = sum(a_)
res = n - sum

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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


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


# Generated by 1.1.4 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:
NM = list(map(int, input().split()))
N, M = NM[0],NM[1]
a = list(map(int, input().split()))
A = sum(a)
if  A> N:
    print(-1)
else:
    print(N - A)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
NM = list(map(int, input().split()))
a = list(map(int, input().split()))
x = 0
for i in range(NM[1]):
    x += a[i]

if x > NM[0]:
    print(-1)
else:
    print(NM[0] - x)

Submission status: Accepted

Solution code:
NM = list(map(int, input().split()))
N, M = NM[0],NM[1]
a = list(map(int, input().split()))
x = 0
for i in range(M):
    x += a[i]

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

Submission status: Accepted

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

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

s = sum(a)
if(s > n):
    print(-1)
else:
    print(max(0,n-s))

Submission status: Accepted

Solution code:
N, M = input().split()
N, M = [int(N), int(M)]
a = list(map(int, input().split()))
x = 0
for i in range(M):
    x += a[i]

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

Submission status: Accepted

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

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

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

if a[0] - c < 0:
  print(-1)
else:
  print(a[0] - c)

Submission status: Accepted

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

for num in range(y):
    x -= A[num]

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

Submission status: Accepted

Solution code:
# Q2
N,M = map(int, input().split())
A = list(map(int, input().split()))
f_days = N - sum(A)
if f_days >= 0:
    print(f_days)
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())
h = map(int, input().split())
H = list(h)
for days in H:
  n -= days
if n>=0:
  print(n)
if n<0:
  print("-1")

Submission status: Accepted

Solution code:
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop
from itertools import permutations, accumulate
from math import sqrt, ceil, floor
from bisect import bisect_left, bisect_right
from copy import deepcopy
from operator import itemgetter
from fractions import gcd
import sys
def I(): return int(input())  # '123' -> 123
def Is(): return map(int, input().split())  # '123 456' -> 123, 456
def LI(): return list(map(int, input().split()))  # '123 456' -> [123, 456]
def TI(): return tuple(map(int, input().split()))  # '123 456' -> (123, 456)
def IR(n): return [I() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def TIR(n): return [TI() for _ in range(n)]
def S(): return input()
def Ss(): return input().split()  # 'aa bb' -> 'aa','bb' or ['aa','bb']
def LS(): return list(input())  # 'abc123' -> ['a','b','c','1','2','3']
def SR(n): return [S() for _ in range(n)]
def SsR(n): return [Ss() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
sys.setrecursionlimit(1000000)
MOD = 1000000007
INF = float('inf')

n, m = Is()
A = LI()

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

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

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
# input
inp_ls = input().split(" ")
n,m = [int(e) for e in inp_ls[:2]]
inp_a_ls = input().split(" ")
a_ls = [int(e) for e in inp_a_ls[:m]]

# calc
rest = n - sum(a_ls)
out = rest if rest >= 0 else -1

# result
print(out)

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
print(max(-1, list(map(int, input().split()))[0] - sum(map(int, input().split()))))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
import math
def i():return int(sys.stdin.readline().replace("\n",""))
def i2():return map(int,sys.stdin.readline().replace("\n","").split())
def s():return str(sys.stdin.readline().replace("\n",""))
def l():return list(sys.stdin.readline().replace("\n",""))
def intl():return [int(k) for k in sys.stdin.readline().replace("\n","").split()]
def lx():return list(map(lambda x:int(x)*-1,sys.stdin.readline().replace("\n","").split()))
def t():return tuple(map(int,sys.stdin.readline().replace("\n","").split()))

def main():
    n,m = i2()
    a = intl()
    print(n-sum(a) if n - sum(a) >= 0 else -1)
if __name__ == "__main__":
    main()

Submission status: Accepted

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

Submission status: Accepted

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

a_sum = sum(A_list)
playday = N-a_sum

if playday < 0:
    print(-1)

else:
    print(playday)

Submission status: Accepted

Solution code:
a,b = map(int,input().split())
c  =[int(i) for  i in input().split()]
su=sum(c)
n = a-su
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()))

homework_day=0

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
l = input().split()
days = 0
for i in l:
  days += int(i)
remain = n-days
if remain <= -2:
  remain = -1
print(remain)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n, m = list(map(int, input().rstrip().split()))
total = sum([int(i) for i in input().rstrip().split()])
result = -1 if n < total else n - total
print(result)

Submission status: Accepted

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

Submission status: Accepted

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

for day in A:
    n -= day

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import sys
rs = lambda: sys.stdin.readline().rstrip()
ri = lambda: int(rs())
lrs = lambda: [_ for _ in rs().split()]
lri = lambda: [int(_) for _ in rs().split()]

N, M = lri()
A = lri()
print(max(N - sum(A), -1))

Submission status: Accepted

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

def main():
    N,M = map(int, input().split())
    A = list(map(int, input().split()))
    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()))
print(max(-1, N - sum(A)))

Submission status: Accepted

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

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

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import math

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

    return 0

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
num_vacation_days, num_homework = map(int, input().split())
day_homework_costs = map(int, input().split())

for day_homework_cost in day_homework_costs:
    num_vacation_days -= day_homework_cost
    if num_vacation_days < 0:
        num_vacation_days = -1
        break

print(num_vacation_days)

Submission status: Accepted

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

sub = N - sum(A)

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

Submission status: Accepted

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


def solve(N: int, M: int, A: "List[int]"):
    print(N - sum(A) if N - sum(A) >= 0 else -1)
    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:
def resolve():
    n, m = map(int, input().split())

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

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

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

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

Submission status: Accepted

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

Submission status: Accepted

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

print(ans)

Submission status: Accepted

Solution code:
# coding:utf-8
n,m =map(int,input().split())
a=list(input().split())

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

if n>=0:
    print(n)

else:
    print(-1)

Submission status: Accepted

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

for i in range(len(a)):
    n = n - int(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()))
sum=0
for i in range(m):
  sum+=a[i]

n=n-sum
if n<=-2:
  n=-1

print(n)

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
dias,tareas=input().split()
dias=int(dias)
tareas=int(tareas)
todas=input().split()
suma=0
for cada in todas:
    suma+=int(cada)
if suma<=dias:
    print(dias-suma)
else:
    print(-1)

Submission status: Accepted

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

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

for a in A:
    N -= a

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

Submission status: Accepted

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


s = n -sum(a)

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

Submission status: Accepted

Solution code:
vacation, homework = map(int, input().split())
daysList = []
days = list(map(int, input().split()))
for i in range(homework):
    daysList.append(days[i])
play_days = vacation - sum(daysList)

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

Submission status: Accepted

Solution code:
#-*- coding: utf-8 -*-
n,m = map(int,input().split())
a = [int(i) for i in 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()))
z = 0
for i in range(M):
  z = z + a[i-1]
if z<=N:
  print(N-z)
else:
  print(-1)

Submission status: Accepted

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

Submission status: Accepted

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

days = N - sum(A)

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n, m =map(int,input().split())
s = list(map(int,input().split()))
free = n
i = 0
while i < m :
     free -= s[i]
     if free < 0 :
          break
     i += 1
if free < 0 :
     print("-1")
elif free >= 0 :
     print(str(free))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#B

inp = input().split(' ')
N = int(inp[0])
M = int(inp[1])

inp = input().split(' ')
Am = [int(i) for i in inp]

residue = N - sum(Am)
print(residue if residue >= 0 else -1)

Submission status: Accepted

Solution code:
x = input()
space_index1 = x.index(' ')

n = int(x[0:space_index1])
m = int(x[space_index1+1:])

x = input()
tmp_space_idx = 0
Ajs = x.split(' ')

sum_ = 0
for aj in Ajs:
  sum_ += int(aj)

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
nums = input().split(' ')
vals = input().split(' ')
num2 = []
val2 = []

for i in range(len(nums)):
  num2.append(int(nums[i]))

for i in range(len(vals)):
  val2.append(int(vals[i]))

sum = 0

for val in val2:
  sum += val

if (sum > num2[0]):
  print("-1")

else:
  print(num2[0] - sum)

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
X, Y  = input().split()
sum = 0
Y2 = input().split()
for i in range(0, int(Y)):
  sum += int(Y2[i])

if int(X)-sum >= 0:
  print(int(X)-sum)
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 range(M):
    S += int(A[i])
print(max(-1,N - S))

Submission status: Accepted

Solution code:
n,m=(int(i) for i in input().split())
t = [int(i) for i in input().split()]
s = sum(t)
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)
if ans >= 0:
  print(ans)
else:
  print("-1")

Submission status: Accepted

Solution code:
import numpy as np

A=list(input().split())


N=int(A[0])
M=int(A[1])

B=list(input().split())

k=0

for i in range(len(B)):
    k+=int(B[i])

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

Submission status: Accepted

Solution code:
[n,m]=list(map(int,input().split()))
alist=list(map(int,input().split()))
work=sum(alist)
ans=n-work
if ans<0:
    ans=-1
print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math

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


def read_ints():
    return list(map(int, input().strip().split(' ')))


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


if __name__ == '__main__':
    print(solve())

Submission status: Accepted

Solution code:
a = list(map(int, input().split()))
n = a[1]
b = list(map(int, input().split()))

Sum = 0
for i in range(n):
  Sum +=b[i]

if Sum <= a[0]:
  print(a[0]-Sum)
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 = map(int, input().split())

d = sum(a)
ans = n-d
if ans >= 0:
    print(ans)
else:
    print("-1")

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
li = input().split()
b = 0
for a in li:
    b = b + int(a)
if n >= b:
    print(n-b)
else:
    print("-1")

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

s = sum(A)

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

Submission status: Accepted

Solution code:
from sys import stdin
def main():
    #入力
    readline=stdin.readline
    N,M=map(int,readline().split())
    A=list(map(int,readline().split()))

    print(max(N-sum(A),-1))
if __name__=="__main__":
    main()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

homework = sum(a)

if homework > N:
    print("-1")

else:
    print(N - homework)

Submission status: Accepted

Solution code:
s = input().split()
N=int(s[0])
M=int(s[1])
A=input().split()


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

Answer = N-sum

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

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!
import sys
readline = sys.stdin.readline
read = sys.stdin.read
 
 
n,m = map(int,input().split())

a = list(map(int, input().split()))  # n個の文字列がリストに格納される

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

Submission status: Accepted

Solution code:
#　N M の形で受け取る
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 の形で受け取る
N,M = map(int, input().split())

#　複数の要素をまとめて受け取る
A = list(map(int, input().split()))

#　リストAの総和を取る
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()))
sum = n
for i in a:
  sum -= i
if sum < 0:
  print(-1)
else:
  print(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()))

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

hwdsum=0
k=0
while k<= m-1:
  hwdsum += a[k]
  k+=1
  
if n-hwdsum>=0:
  print(str(n-hwdsum))
  
else:
  print(str(-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_data = input()
a = a_data.split(' ')

sum = 0
# sum = sum(a)
for item in a:
  sum += int(item)

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

Submission status: Accepted

Solution code:
NM = [int(i) for i in input().split()]
A = [int(i) for i in input().split()]

N = NM[0]
M = NM[1]

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

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

Submission status: Accepted

Solution code:
import sys
N, M = map(int, sys.stdin.readline().split())
A = list(map(int, sys.stdin.readline().split()))

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = [list(map(int, input().split())) for i in range(2)]

N = n[0][0]
M = n[0][1]
A = n[1]
days = 0
for i in A:
    days += i

day = N - days
if day < 0:
    print("-1")
else:
    print(day)