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

sum = 0
for a in A:
  sum += a

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

Submission status: Accepted

Solution code:
#


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


if __name__ == '__main__':
    main()

Submission status: Accepted

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

print(N - sum(A))

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
day, num = map(int,input().split())
work = [int(x) for x in input().split()]

sum = sum(work)

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
x = input().split()
c  =int(x[0])
v = input().split()
f = 0
for i in v:
  f += int(i)
m = c - f
if m < 0:
  print('-1')
else:
  print(m)

Submission status: Accepted

Solution code:
(N, M) = list(map(int, input().split()))
A = list(map(int, input().split()))
total = 0
for a in A:
    total += a

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
N, M = map(int, input().split())
A_list = list(map(int, input().split()))

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

Submission status: Accepted

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

Submission status: Accepted

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

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

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:
import numpy as np
N, M = map(int, input().split())
data = np.array(input().split(), dtype=np.int64)

#height = [int(input()) for _ in range(M)]
sum = N - np.sum(data)

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

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
def main():
  n,m=map(int,input().split())
  a=list(map(int,input().split())) #横一列リスト
  ans=0
  for i in range(m):
    ans+=a[i]
  if ans<=n:
      print(n-ans)
  else:
      print('-1')
main()

Submission status: Accepted

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

day = sum(A)

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

Submission status: Accepted

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

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

answer = -1
if n >= sum:
  answer = n - sum

print(answer)

Submission status: Accepted

Solution code:
import sys

def get_ints(): return map(int, sys.stdin.readline().strip().split())
def get_array(): return list(get_ints())
def input(): return sys.stdin.readline().strip()


n, m = get_ints()
Arr = get_array()
Sum = sum(Arr)
if Sum > n:
	print(-1)
else:
	print(n - Sum)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
params0 = list(map(lambda x: int(x), input().split(' ')))
params1 = list(map(lambda x: int(x), input().split(' ')))

days = params0[0]
required = sum(params1)
if days >= required:
    print(days - required)
else:
    print(-1)

Submission status: Accepted

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

Submission status: Accepted

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

    joy = N-sum(A)
    if joy >= 0:
        print(joy)
    else:
        print(-1)
if __name__ == '__main__':
    solve()

Submission status: Accepted

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

if __name__ == '__main__':
  main()

Submission status: Accepted

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

Submission status: Accepted

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

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

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=sum+a[i]

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

Submission status: Accepted

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


if __name__ == "__main__":
    main()

Submission status: Accepted

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

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

Submission status: Accepted

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

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
N,_ = map(int, sys.stdin.readline().split())
A = map(int, sys.stdin.readline().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 = input()
listA = A.split()

tmp = []
for i in listA:
    tmp.append(int(i))

ans = N - sum(tmp)

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

Submission status: Accepted

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


if __name__ == '__main__':
    main()

Submission status: Accepted

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


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
a = list(map(int, input().split()))
s = 0
f = True
for i in a:
    if s + i <= n:
        s += i
    else:
        f = False
if f:
    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):
    print("-1")
else:
    print(n-sum(a))

Submission status: Accepted

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

Submission status: Accepted

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

def main():
  n, m = map(int, input().split())
  arg = [int(i) for i in input().split()]
  for i in arg:
    n -= i
    if n < 0:
      return -1
    
  return n
  
if __name__ == '__main__':
  print(main())

Submission status: Accepted

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

Submission status: Accepted

Solution code:
a, b = list(map(int, input().split()))
c = list(map(int, input().split()))
for i in range(b):
    a = a-c[i]

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

Submission status: Accepted

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

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


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
A = [int(a) for a in input().split()]
asum = sum(A)
if N >= asum:
    print(N - asum)
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)
else:
  print(ans)

Submission status: Accepted

Solution code:
import sys
from math import factorial
from collections import Counter
from fractions import Fraction
import heapq, bisect, fractions
import math
import itertools
sys.setrecursionlimit(10 ** 5 + 10)
INF = 10**15 +5
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()))
MOD = 10**9 + 7


N, M = MAP()
A = LIST()
if sum(A)>N:
    print(-1)
else:
    print(N-sum(A))

Submission status: Accepted

Solution code:
n, m = [int(c) for c in input().split()]
a = [int(c) for c in input().split()]
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()))
n-=sum(a)
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):
  print(-1)
else:
  print(N-sum(A))

Submission status: Accepted

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

A = map(int,input().split())
b = N-sum(A)
print(-1 if b < 0 else b)

Submission status: Accepted

Solution code:
n,m = map(int,input().split())
a_list = list(map(int,input().split()))
sum_a = sum(a_list)
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 = 0
for b in range(m):
  total += a[b]
  
if n - total >= 0:
  print(n-total)
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()))

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

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

Submission status: Accepted

Solution code:
if __name__ == "__main__":
  n, m = map(int, input().split())
  a_list = [int(i) for i in input().split()]
  hw_sum = sum(a_list)
  if hw_sum > n:
    print(-1)
    exit()
  else:
    print(n-hw_sum)

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:
n,m = map(int,input().split())
all = list(map(int,input().split()))
result = 0

for i in range(m):
    result += all[i]

result = max(-1 ,n-(result))
print(result)

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:
line1 = input().split()
n = int(line1[0])
m = int(line1[1])

sum = 0
a = input().split()
for i in range(m):
  sum += int(a[i])

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

print(ans)

Submission status: Accepted

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

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

subjects = sum(A)

if subjects > N:
    print(-1)

else:
    print(N-subjects)

Submission status: Accepted

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

Submission status: Accepted

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

for i in range(0,M):
  r+=list[i]

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

Submission status: Accepted

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

ans=-1
SUM=0
for i in range(M):
    SUM += A[i]
if SUM <= N:
    ans = N - SUM

print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

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

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

Submission status: Accepted

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

from sys import stdin


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

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


if __name__ == "__main__":
    main()

Submission status: Accepted

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

t=0
for i in li:
    t+=int(i)
if n-t < 0:
    print(-1)
else:
    print(n-t)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

s = [int(e) for e in input().split()]
#print(s)

sm = sum(s)

if n < sm :
  print('-1')
else:
  print( n - sm )

Submission status: Accepted

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

vacation = n-sum(As)
if vacation < 0:
	print('-1')
else:
	print(vacation)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# coding: utf-8

day = input().split(" ")
natsu = int(day[0])
kazu = int(day[1])
syuku = input().split(" ")
total = 0
for i in range(len(syuku)):
    total += int(syuku[i])
if natsu < total:
    print(-1)
else:
    print(natsu- total)

Submission status: Accepted

Solution code:


days, task_cnt = map(int, input().split())
tasks = [int(i) for i in input().split()]

aa = days - sum(tasks)

if aa < 0 :
    print("-1")
else:
    print(aa)

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 = [int(x) for x in input().split()]
A = [int(x) for x in input().split()]

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

Submission status: Accepted

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

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
d = input().split(" ")
n = int(d[0])
m = int(d[1])
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 = map(int, input().split())

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

Submission status: Accepted

Solution code:
def resolve():
    N, M = map(int, input().split())
    A = list(map(int, input().split()))
    ans = N - sum(A)

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

    print(ans)


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

Submission status: Accepted

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

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

Submission status: Accepted

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

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

print(N - A) if N - A >= 0 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())
l=list(map(int,input().split()))

sum=0
for i in range(m):
  sum+=l[i]

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

Submission status: Accepted

Solution code:
a,b=input().split()
a=int(a)
b=int(b)
x=[]
c=input().split()
for i in range(b):
    x.append(int(c[i]))
z=sum(x)
if z<= a:
    print(a-z)
else:
    print(-1)

Submission status: Accepted

Solution code:
n, m = [int(i) for i in 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:
import sys
N,M = list(map(int, sys.stdin.readline().rstrip().split())) 
A = list(map(int, sys.stdin.readline().rstrip().split())) 

s = 0
for n in range(M):
  s += A[n]
  
s = N - s
if s < 0:
  print(-1)
else:
  print(s)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
# coding=UTF-8
from collections import deque
from operator import itemgetter
from bisect import bisect_left, bisect
import itertools
import sys
import math
sys.setrecursionlimit(10**6)
input = sys.stdin.readline
# 文字列には注意


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


if __name__ == '__main__':
    main()

Submission status: Accepted

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

N = int(N)
M = int(M)
#print(N,M,A)

sum = 0
for i in A:
    sum += int(i)

#print(sum)

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

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=[int(x) for x in input().split()]
a=[int(x) for x in 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 = list(map(int, input().split()))
    if sum(A) <= N:
        print(N - sum(A))
    else:
        print(-1)
    
    
if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
input_line1 = input()
input_line2 = input()

n, m = map(int, input_line1.split())
a_list = map(int, input_line2.split())

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

Submission status: Accepted

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

Submission status: Accepted

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

ans = N - sum(A)

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

s = sum(l)

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

Submission status: Accepted

Solution code:
import math
import operator as op
from functools import reduce

def ncr(n, r):
    r = min(r, n-r)
    numer = reduce(op.mul, range(n, n-r, -1), 1)
    denom = reduce(op.mul, range(1, r+1), 1)
    return numer / denom
"""
int(input())
map(int,input().split())
list(map(int,input().split()))
"""


            
       

t=1
for term in range(1,t+1):
    n,m=map(int,input().split())
    A=list(map(int,input().split()))
    s=sum(A)
    if(n>=s):
        print(n-s)
    else:
        print(-1)

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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


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

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

Submission status: Accepted

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


def solve(N: int, M: int, A: "List[int]"):
    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():
    N, M = map(int,input().split())
    a = list(map(int,input().split()))

    sum = 0
    for i in range(M):
        sum += a[i]
    left = N - sum
    if left >= 0:
        print(left)
    else:
        print(-1)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
# Code for B - Homework
# Use input() to fetch data from STDIN
[n, m] = 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(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())
li = list(map(int, input().split()))

s = sum(li)
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(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=list(map(int,input().split()))
sum_A=sum(A_list)
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(ans)
else:
    print(-1)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
# python3
# -*- coding: utf-8 -*-
import sys
import math
import bisect
from fractions import gcd
from itertools import count, permutations
from functools import lru_cache
from collections import deque, defaultdict
from pprint import pprint

INF = float('inf')

ii = lambda: int(input())
mis = lambda: map(int, input().split())
lmis = lambda: list(mis())
lmtx = lambda h: [list(map(int, lmis())) for _ in range(h)]
sys.setrecursionlimit(1000000000)


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


# main
n, m = mis()
alist = lmis()

freedays = n - sum(alist)

if freedays < 0:
    print('-1')
else:
    print(str(freedays))

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
a = 0
alist = list(map(int, input().split()))
for _ in alist:
  a += _

if n < a:
  print('-1')

else:
  ans = n - a
  print(ans)

Submission status: Accepted

Solution code:
import numpy as np

n,m = map(int, input().split())
arr = [int(_) for _ in input().split()]

if n < np.sum(arr):
  print(-1)
else:
  print(n-np.sum(arr))

Submission status: Accepted

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

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

Submission status: Accepted

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

def main():
    *I, = map(int, open(0).read().split())
    N = I[0]
    M = I[1]
    A = I[2:]

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


main()

Submission status: Accepted

Solution code:


n, m = [0] * 2
a = []

def format_input(filename = None):
	global n, m
	global a
	if filename == None:
		n, m = list(map(int, input().split()))
		a = list(map(int, input().split()))

	elif filename == '__random__':
		from random import randint as rng
		n = rng(1, 10**6)
		m = rng(1, 10**4)
		a = [rng(1, 10**4) for i in range(m)]
		print(n, m)
		print(' '.join(list(map(str, a))))

def get_answer():
	answer = max(n - sum(a), -1)
	return answer

if __name__ == '__main__':
	format_input()

	ans = get_answer()
	print(ans)

Submission status: Accepted

Solution code:
import numpy as np
if __name__ == "__main__":
    # 入力パターン．
    # 先に要素数Nが与えられて，その数読み込むパターン
    ### N
    ### a_1 a_2 a_3 ... a_N
    N, M = map(int, input().split())
    # int型のリスト
    line = np.array(list(map(int, input().rstrip().split(' '))))
    ans = N-line.sum()
    if ans >= 0:
        print(ans)
    else:
        print(-1)

Submission status: Accepted

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

cost = list(map(int,input().split()))
flg = True

for i in cost:
    n -= i
    if n < 0:
        print(-1)
        flg = False
        break
if flg:
    print(n)