Problem:


Score : 200 points

Problem Statement

Takahashi has N days of summer vacation.

His teacher gave him M summer assignments. It will take A_i days for him to do the i-th assignment.

He cannot do multiple assignments on the same day, or hang out on a day he does an assignment.

What is the maximum number of days Takahashi can hang out during the vacation if he finishes all the assignments during this vacation?

If Takahashi cannot finish all the assignments during the vacation, print -1 instead.

Constraints

1 \leq N \leq 10^6

1 \leq M \leq 10^4

1 \leq A_i \leq 10^4

Input

Input is given from Standard Input in the following format:

N M
A_1 ... A_M

Output

Print the maximum number of days Takahashi can hang out during the vacation, or -1.

Sample Input 1

41 2
5 6

Sample Output 1

30

For example, he can do the first assignment on the first 5 days, hang out on the next 30 days, and do the second assignment on the last 6 days of the vacation. In this way, he can safely spend 30 days hanging out.

Sample Input 2

10 2
5 6

Sample Output 2

-1

He cannot finish his assignments.

Sample Input 3

11 2
5 6

Sample Output 3

0

He can finish his assignments, but he will have no time to hang out.

Sample Input 4

314 15
9 26 5 35 8 9 79 3 23 8 46 2 6 43 3

Sample Output 4

9



Sample input:
41 2
5 6


Sample output:
30

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
d,n=[int(x) for x in input().split()]
x = [int(x) for x in input().split()]
tot=d-sum(x)
if(tot>=0):print(tot)
else:print(-1)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from heapq import *
import sys
from collections import *
from itertools import *
from decimal import *
import copy
from bisect import *
import time
import math
def gcd(a,b):
    if(a%b==0):return(b)
    return (gcd(b,a%b))
sys.setrecursionlimit(10**7)
input=lambda :sys.stdin.readline().rstrip()
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()))
v = n
for d in a:
    v -= d
print(v if v>=0 else -1)

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
list = input().split()
day = 0
for x in list:
    day = day + int(x)
ans = N - day
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()))
q = sum(a)
if n - q >=0:
    print(n-q)
else:
    print('-1')

Submission status: Accepted

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

Submission status: Accepted

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

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
k,p = map(int,input().split())
H = list(map(int,input().split()))
kk=sum(H)
if k-kk >= 0:
    print(k-kk)
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:
N,M=map(int,input().split())
A=[0]*M
day=0
A= [int(i) for i in input().split()]
for cnt in range(M):
  day+=A[cnt]
  if day>N:
    ans=-1
    break
ans=N-day
if ans<0:
  print("-1")
else:
  print(ans)

Submission status: Accepted

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

a = sum(list(map(int, input().split()))) 
ans = n - 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(' ')))

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

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:
# coding: utf-8
# Your code here!
import numpy as np
import math

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

A = map(int, input().split())
count = 0
for a in A:
    count += a
#print(count)
if N-count >= 0:
    print(N-count)
else:
    print('-1')

Submission status: Accepted

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

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

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

Submission status: Accepted

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

if __name__ == '__main__':
    main()

Submission status: Accepted

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

asoberu = n - homeworks
asoberu = asoberu if asoberu >= 0 else -1

print(asoberu)

Submission status: Accepted

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


ans = n
for i in range(m):
    ans -= lis[i]
if ans >= 0:
    print(ans)
else:
    print("-1")

Submission status: Accepted

Solution code:
import numpy as np
n, m = list(map(int, input().split()))
a = np.array(list(map(int, input().split())))

s = np.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 n in A:
    N-=n
if N>=0:
    print(N)
else:
    print(-1)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
i,ii = map(int,input().split())

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

sum = sum(l)

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

Submission status: Accepted

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

if n < sum(a_list):
    print('-1')
else:
    print(n - sum(a_list))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
il1 = input().split()
il2 = input().split()

il1 = [int(i) for i in il1]
il2 = [int(i) for i in il2]

N = il1[0]
M = il1[1]

A = il2

for a in il2:
    N = N - a

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

Submission status: Accepted

Solution code:
nm = list(map(int, input().split()))
a = list(map(int, input().split()))
asobi=nm[0]
for i in range(nm[1]):
    asobi-=a[i]

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

Submission status: Accepted

Solution code:
n,m = input().split()
ai = input().split()
a = 0
for i in ai:
    a=a+int(i)
if int(n)-a>=0:
    print(int(n)-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())
ls_a = list(map(int,input().split()))

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math
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(int(N-sum))

Submission status: Accepted

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

Submission status: Accepted

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

day_sum = sum(A)

ans = N - day_sum

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

else:
    print(str(ans))

Submission status: Accepted

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

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

Submission status: Accepted

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

import sys
import math


sys.setrecursionlimit(10 ** 6)

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

a_sum = sum(A)

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

Submission status: Accepted

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

Submission status: Accepted

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

hw = sum(A)
play = N - hw

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
lis = input().split()
N, M = int(lis[0]), int(lis[1])
A_lis = input().split()

task_time = sum([int(i) for i in A_lis])

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from collections import Counter
import sys

sys.setrecursionlimit(10 ** 6)

mod = 1000000007
inf = int(1e18)

dx = [0, 1, 0, -1]
dy = [1, 0, -1, 0]


def inverse(a):
    return pow(a, mod - 2, mod)


def usearch(x, a):
    lft = 0
    rgt = len(a) + 1
    while rgt - lft > 1:
        mid = (rgt + lft) // 2
        if a[mid] <= x:
            lft = mid
        else:
            rgt = mid
    return lft

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

main()

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:
#JMD
#Nagendra Jha-4096

 
import sys
import math

#import fractions
#import numpy
 
###File Operations###
fileoperation=0
if(fileoperation):
    orig_stdout = sys.stdout
    orig_stdin = sys.stdin
    inputfile = open('W:/Competitive Programming/input.txt', 'r')
    outputfile = open('W:/Competitive Programming/output.txt', 'w')
    sys.stdin = inputfile
    sys.stdout = outputfile

###Defines...###
mod=1000000007
 
###FUF's...###
def nospace(l):
    ans=''.join(str(i) for i in l)
    return ans
 
 
 
##### Main ####
t=1
for tt in range(t):
    #n=int(input())
    n,m= map(int, sys.stdin.readline().split(' '))
    a=list(map(int,sys.stdin.readline().split(' ')))
    if(sum(a)>n):
        print(-1)
    else:
        print(n-sum(a))
    
    
#####File Operations#####
if(fileoperation):
    sys.stdout = orig_stdout
    sys.stdin = orig_stdin
    inputfile.close()
    outputfile.close()

Submission status: Accepted

Solution code:
n, m = map(int,input().split())
w = tuple(map(int,input().split())) 
day = 0
for d in w:
    day += d
ans = n - day
if (ans >= 0):
    print(ans)
else:
    print(-1)

Submission status: Accepted

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

days_sum = sum(A)



ans = N - days_sum

if ans < 0:
  ans = -1

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import os

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

if __name__ == "__main__":
        main()

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

Submission status: Accepted

Solution code:
N_M = input().split(" ")
total = 0
s = input().split(" ")

for i in range(int(N_M[1])):
    total += int(s[i])
result = int(N_M[0]) - total
if result < 0:
    print(-1)
else:
    print(result)

Submission status: Accepted

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

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
import sys
stdin = sys.stdin

     
ns = lambda: stdin.readline().rstrip()
ni = lambda: int(stdin.readline().rstrip())
nm = lambda: map(int, stdin.readline().split())
nl = lambda: list(map(int, stdin.readline().split()))
N,M=nm()
A=nl()

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

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


if __name__ == "__main__":
    main()

Submission status: Accepted

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

Submission status: Accepted

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

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

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

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

Submission status: Accepted

Solution code:
def main(N, M, A):
    memo = N - sum(A)
    if memo >= 0:
        return memo
    else:
        return -1

if __name__ == '__main__':
    N, M = list(map(int, input().split()))
    A = list(map(int, input().split()))
    # N = 314
    # M = 15
    # A = list(map(int, "9 26 5 35 8 9 79 3 23 8 46 2 6 43 3".split()))
    # print(N, M, A)
    print(main(N, M, 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=[int(x) for x in input().split()]
A=[int(x) for x 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())
list_a = list(map(int, input().split()))
homework = sum(list_a)
if homework <= n:
    print(n - homework)
else:
    print(-1)

Submission status: Accepted

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

main()

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import math

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

tot = sum(Ai)

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
days,num = map(int,input().split())
homeworks = list(map(int,input().split()))

temp = sum(homeworks)

if temp > days:
    print(-1)
else:
    print(days-temp)

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

A_sum = sum(A_list)
play = N - A_sum
if play >= 0:
    print(play)
else:
    print(-1)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

free = N - sum(A)

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

Submission status: Accepted

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

li_a = list(map(int, input().split(" ")))
days = 0

for i in range(M):
  days += li_a[i]

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

Submission status: Accepted

Solution code:
import math

def solution():
    n, m = map(int, input().split())
    a = [int(aa) for aa in input().split()]
    ans = n - sum(a)
    if ans < 0:
        print('-1')
    else:
        print(ans)

solution()

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

ans = N - sum(cons)
if(ans < 0):
        ans = -1

print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

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

N -= sum(a_ar)

if N < 0:
  N = -1

print(N)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def main():
  #n = int(input())
  #s = input()
  #s = input().split()
  n,m = list(map(int,input().split()))
  a =  list(map(int,input().split()))
  #a = [input() for i in range(n)]
  #a = [int(input()) for i in range(n)]
  #a = [input().split() for i in range(n)]
  #a = [list(map(int,input().split())) for i in range(n)]
  ans = 0
  count = 0
  lis = []
  
  for i in a:
    ans += i  
  if ans > n:
    print(-1)
  else:
    print(n-ans)
if __name__ == '__main__':
  main()

Submission status: Accepted

Solution code:
# import sys
# sys.setrecursionlimit(10 ** 6)
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 LLI(rows_number): return [LI() for _ in range(rows_number)]


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

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


if __name__ == '__main__':
    solve()

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

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

Submission status: Accepted

Solution code:
N,M=map(int,input().split())
A=list(map(int,input().split()))
s=0
for i in A:
    s+=i
a=N-s
if a>=0:
    print(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())
A=list(map(int,input().split()))

nissuu=sum(A)

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

Submission status: Accepted

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

if b<=n:
    print(n-b)
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 = N
    for i in range(M):
        ans -= A[i]
    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()))

sumA = sum(A)
ans = N-sumA
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()))

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

Submission status: Accepted

Solution code:
import sys
n,m=map(int,input().split())
A=list(map(int,input().split()))
ans=n
for a in A:
  ans-=a
  if ans<0:
    print('-1')
    sys.exit()
print(ans)

Submission status: Accepted

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

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

ans = X - sum(s)

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

Submission status: Accepted

Solution code:
t=list(map(int,input().split(' ')))
u=list(map(int,input().split(' ')))
x=t[0]-sum(u)
if x>=0:
    print(x)
else:
    print('-1')

Submission status: Accepted

Solution code:

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
nm = input().split(" ")
n = int(nm[0])
m = nm[1]

a = input().split(" ")
res = 0
for ai in a:
    res += int(ai)
    if res > n:
        print("-1")
        exit()

print(n-res)

Submission status: Accepted

Solution code:
import math

class abc_163:
    
    def __init__(self):
        pass
    
    def A(self):
        r=int(input())
        print(2*math.pi*r)
    
    def B(self):
        NM=list(map(int,input().split()))
        A=list(map(int,input().split()))
        
        if NM[0]-sum(A)>=0:print(NM[0]-sum(A))
        else:print("-1")
    
if __name__=='__main__':
    obj=abc_163()
    obj.B()

Submission status: Accepted

Solution code:
import sys

lines = sys.stdin.readlines()

X = lines[0].split(' ')
Y = lines[1].split(' ')

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

d = 0
for i in range(M):
    d = d + int(Y[i])

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math
import sys

stdin = sys.stdin

ns = lambda: stdin.readline().rstrip()
ni = lambda: int(stdin.readline().rstrip())
nm = lambda: map(int, stdin.readline().split())
nl = lambda: list(map(int, stdin.readline().split()))
mod = 10**9 + 7 
sys.setrecursionlimit(1000010)


N,M = nm()
A  = nl()
ans = max(-1,N - sum(A))
print(ans)

Submission status: Accepted

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

if kakaru <= a:
    print(a - kakaru)
else:
    print("-1")

Submission status: Accepted

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

#intの場合
L, R = map(int,input().split())

#intの場合
huga = list(map(int, input().split()))


S = L - sum(huga)
if S < 0 :
  S = -1

print(S)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import numpy as np


def main():
    # 整数の入力
    N, M = map(int, input().split())
    A = list(map(int, input().split()))
    ans = N - sum(np.array(A))
    if ans < 0:
        print('-1')
    else:
        print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
from collections import defaultdict, Counter

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:
# -*- coding: utf-8 -*-
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())
homework = list(map(int, input().split()))

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

Submission status: Accepted

Solution code:
Days , number = map(int,input().split())
A_list = list(map(int,input().split()))

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
out, n = map(int,input().split())
l = map(int,input().split())
for v in l:
    out -= v
if out < 0:
    out = -1        
print(out)

Submission status: Accepted

Solution code:
from sys import stdin, stdout
import math,sys
from itertools import permutations, combinations
from collections import defaultdict,deque,OrderedDict
import bisect as bi
import heapq 
'''
#------------------PYPY FAst I/o--------------------------------#

def I():return (int(stdin.readline()))
def In():return(map(int,stdin.readline().split()))
'''
#------------------Sublime--------------------------------------#

#sys.stdin=open('input.txt','r');sys.stdout=open('output.txt','w');
def I():return (int(input()))
def In():return(map(int,input().split()))

def find_gt(a, x):
    #'Find leftmost value greater than x'
    i = bi.bisect_right(a, x)
    if i != len(a):
        return i
    else:
        return -1


def main():
    try:
        a,b=In()
        l=list(In())
        n=sum(l)
        if a-n<0:
            print(-1)
        else:
            print(a-n)
            
    except:
        pass
M = 998244353
P = 1000000007

if __name__ == '__main__':
    main()

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
N = [int(e) for e in input().split()]
nums = [int(t) for t in input().split()]
sums = 0
for k in range(0,N[1]):
    sums += nums[k]
if(sums > N[0]):
    print(-1)
else:
    print(N[0] - sums)

Submission status: Accepted

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

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