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:
S,N=input().split()
p=input().split()
s=0
i=1
while(i<=int(N)):
    s=s+int(p[i-1])
    i=i+1
x=int(S)-s
if(x>=0):
    print(x)
else:
    print(-1)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n, m, *A = map(int, open(0).read().split())
ans = n-sum(A)
print(ans if ans >= 0 else -1)

Submission status: Accepted

Solution code:
import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines

def main():
    N,M = map(int, readline().split())
    A = [int(i) for i in readline().split()]

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


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
N,M=list(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()))

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

Submission status: Accepted

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

n = input_list[0]
m = input_list[1]
a_i_list = list(map(int, input().split(" ")))


a_i_sum = sum(a_i_list)

result = n - a_i_sum

if result < 0:
    result = -1

print(result)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
j=list(map(int,input().split())) 
n=j[0]
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())
A = list(map(int,input().split()))
free = n - sum(A)
if free < 0:
  print(-1)
else:
  print(free)

Submission status: Accepted

Solution code:
N,M = list(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:
import math, sys
from bisect import bisect_left, bisect_right
from collections import Counter, defaultdict, deque
from copy import deepcopy
from functools import lru_cache
from heapq import heapify, heappop, heappush
from itertools import accumulate, combinations, permutations
input = sys.stdin.readline
mod = 10**9 + 7
ns = lambda: input().strip()
ni = lambda: int(input().strip())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))

def main():
    n, m = nm()
    a = nl()

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


if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

c = sum(arr)

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

Submission status: Accepted

Solution code:

def resolve():
    N, K = 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__":
    resolve()

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

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
A = list(map(int, input().split()))
days = 0
for a in A:
    days += a
result = N - days
if result < 0:
    print("-1")
else:  
    print(str(result))

Submission status: Accepted

Solution code:
if __name__ == "__main__":
    N, M = map(int, input().split())
    A = list(map(int, input().split()))
    ret = -1
    A_sum = sum(A)
    if not N - A_sum < 0:
        ret = N - A_sum
    print(int(ret))

Submission status: Accepted

Solution code:
i = list(map(int, input().split()))
s = list(map(int, input().split()))
N = i[0]
A = sum(s)
d = N - A
if d < 0:
  print("-1")
else:
  print(d)

Submission status: Accepted

Solution code:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

n, m, *a = map(int, read().split())
print(max(-1, n - sum(a)))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math

def Next(): return input()
def NextInt(): return int(Next())
def NextInts(): return map(int,input().split())
def Nexts(): return map(str,input().split())
def NextIntList(): return list(map(int,input().split()))
def RowInts(n): return [input() for i in range(n)]

n,m = NextInts()
a = NextIntList()
ans = 0
for i in range(m):
    ans += a[i]
print(max(-1, n-ans))

Submission status: Accepted

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

Submission status: Accepted

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

a = 0
for i in range(n):
    a += a_list[i]

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math
a=input().split()
n,m=int(a[0]),int(a[1])
f=list(map(int,input().split()))
s=0
fl=0
s=sum(f)
if(n>=s):
  print(n-s)
else:
  print("-1")

Submission status: Accepted

Solution code:
n , k = map(int,input().split())
a = list(map(int,input().split()))
sum = 0
for ele in a:
    sum += ele
if sum <= n:
    print(n-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:
n, m = map(int, input().split())
A = [int(i) for i in input().split()]
if n < sum(A):
  print(-1)
else:
  print(n-sum(A))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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


def solve(N: int, M: int, A: "List[int]"):
    a_sum = N
    for x in A:
        a_sum -= x

    if a_sum < 0:
        print(-1)
    else:
        print(a_sum)
    return


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

if __name__ == '__main__':
    main()

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import sys

sys.setrecursionlimit(10 ** 7)
rl = sys.stdin.readline


def solve():
    N, M = map(int, rl().split())
    A = list(map(int, rl().split()))
    
    ans = N - sum(A)
    print(ans if 0 <= ans else -1)


if __name__ == '__main__':
    solve()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
(a,b) = input().split()

a = int (a)
b = int (b)

num_list =[]

num_list.extend(list(map(int,input().split())))

x = num_list
c = sum(x)

d = a - c

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

Submission status: Accepted

Solution code:
N,M = (input()).split()
task = input().split()
list1 = []
sum = 0
for i in task:
    list1.append(i)
for j in list1:
    sum = sum + int(j)
result = int(N) - sum
if result < 0:
    print(-1)
else:
    print(result)

Submission status: Accepted

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

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

    total_A = sum(A)

    ans = N - total_A

    if ans >= 0:
        print('{}'.format(ans))
    else:
        print('{}'.format(-1))



if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import bisect
import copy
import heapq
import sys
import itertools
import math
import queue
input = sys.stdin.readline
sys.setrecursionlimit(1000000)
mod = 10 ** 9 + 7

def read_values(): return map(int, input().split())
def read_index(): return map(lambda x: int(x) - 1, input().split())
def read_list(): return list(read_values())
def read_lists(N): return [read_list() for n in range(N)]
def init_dp1(init, N): return [init for _ in range(N)]
def init_dp2(init, N, M): return [[init for _ in range(M)] for _ in range(N)]


class V:
    def __init__(self, f, v=None):
        self.f = f
        self.v = v
 
    def __str__(self):
        return str(self.v)
 
    def ud(self, n):
        if n is None:
            return

        if self.v is None:
            self.v = n
            return
        self.v = self.f(self.v, n) 


def main():
    N, M = read_values() 
    A = read_list()

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


if __name__ == "__main__":
    main()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

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())
l=(map(int,input().split()))
c=sum(l)
if c <=n:
    print(n-c)
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(N-sum(a))
else:
    print('-1')

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
import math
import bisect

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

if __name__ == "__main__":
    main()

Submission status: Accepted

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

N = int(N)
M = int(M)

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


if sum(a) < N:
    print(N-sum(a))

if sum(a) == N:
    print(0)

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
# import math

s = [input() for i in range(2)]
n = int(s[0].split()[0])
m = int(s[0].split()[1])
a = list(map(int, s[1].split()))

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

print(n)

Submission status: Accepted

Solution code:
from sys import stdin, setrecursionlimit, stdout
#setrecursionlimit(1000000)
from collections import deque
from math import sqrt, floor, ceil, log, log2, log10, pi, gcd, sin, cos, asin
def ii(): return int(stdin.readline())
def fi(): return float(stdin.readline())
def mi(): return map(int, stdin.readline().split())
def fmi(): return map(float, stdin.readline().split())
def li(): return list(mi())
def lsi():
    x=list(stdin.readline())
    x.pop()
    return x
def si(): return stdin.readline()
mod=1000000007
res=['YES', 'NO']
############# CODE STARTS HERE #############
n, m=mi()
a=li()
print(max(-1, n-sum(a)))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
vacDuration, homeworkAmount = map(int, input().split())
daySpent = list(map(int, input().split()))
sum_daySpent = 0
for i in daySpent:
    sum_daySpent += i
if sum_daySpent > vacDuration:
    print('-1')
else:
    print(vacDuration - sum_daySpent)

Submission status: Accepted

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

rest = N - sum(A_int)
if rest >= 0:
  print(rest)
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:
inp=[int(x) for x in input().split()]
n,m=inp[0],inp[1]
arr=[int(x) for x in input().split()]
if sum(arr)>n:
  print(-1)
else:
  print(n-sum(arr))

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
n_vacations, n_an = list(map(int, input().split()))
an = list(map(int, input().split()))
out = n_vacations - sum(an) 
if out < 0:
  print("-1")
else:
  print(out)

Submission status: Accepted

Solution code:
import sys

days, N = map(int, sys.stdin.readline().split())

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

ans = int(days - sum(a))

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

ans=(N-int(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()))
B=0
for i in range(len(A)):
    B=B+A[i]
C=N-B
if C>=0:
    print (C)
else:
    print ("-1")

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
import math
from collections import defaultdict
from bisect import bisect_left, bisect_right

sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]

mod = 10**9 + 7

def I(): return int(input())
def LI(): return list(map(int, input().split()))
def LIR(row,col):
    if row <= 0:
        return [[] for _ in range(col)]
    elif col == 1:
        return [I() for _ in range(row)]
    else:
        read_all = [LI() for _ in range(row)]
        return map(list, zip(*read_all))

#################

N,M = LI()
A = LI()

s = sum(A)
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()))
t = sum(a)
print(max((N - t),-1))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def homework(M,array):
  if sum(array) > M:
    return -1
  else:
    return M - sum(array)


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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
A = map(int, input().split())
hw = 0
for i in A:
    hw += i
ans = N - hw

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

Submission status: Accepted

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

if (sum(a) < n):
    print(n - sum(a))
elif (sum(a) == n):
    print(sum(a) - n)
elif (sum(a) > n):
    print(-1)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
A = input().split(" ")
B = input().split(" ")
b = 0
s = 0

for i in range(int(A[1])):
  s = s + int(B[b])
  b += 1

if int(A[0]) >= s:
  print(int(A[0]) - s)
else:
  print(-1)

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

a_sum=0

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

Submission status: Accepted

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

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:
input_= list(map(int, input().split()))
timeofholiday=input_[0]
sum=0
homework_num=input_[1]
que=list(map(int, input().split()))
for i in que:
  sum+=i
  
if sum > timeofholiday:
  print("-1")
else:
  print(timeofholiday-sum)

Submission status: Accepted

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

ret = N - sum(list_i)
if ret < 0:
  ret = -1
print(ret)

Submission status: Accepted

Solution code:
import sys
import os
import math

def file_input():
    f = open('input.txt', 'r')
    sys.stdin = f

def main():
    #file_input()

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

    for i in range(M):
        for j in range(A[i]):
            N -= 1
            if N==-1 :
                break
        else:
            continue
        break

    print(N)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

all_homework_day = sum(a)

if all_homework_day <= n:
    play_day = n - all_homework_day
else:
    play_day = -1

print(play_day)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import random

s = list(map(int, input().split()))
# s[0] = 夏休みの日数
# s[1] = 宿題の個数
a = list(map(int, input().split()))

N = s[1]

if s[0]-sum(a) >= 0:
  print(s[0]-sum(a))
else:
  print("-1")

Submission status: Accepted

Solution code:
input1 = input()
daylist = input1.split()
days = daylist[0]

input2 = input()
tasklist = input2.split()

sum = 0
for task in tasklist:
  sum += int(task)

calc = int(days) - sum
if calc >= 0:
  print(calc)
else:
  print("-1")

Submission status: Accepted

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

A = input().split(" ")

total = 0

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

play = N - total
if play < 0:
  play = -1

print(play)

Submission status: Accepted

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

Submission status: Accepted

Solution code:

N, M = map(int, input().split())
work = []
[work.append(x) for x in map(int, input().split())]

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

total = 0
for n in range(int(M)):
    total += int(A[n])

ans = -1 if total > int(N) else int(N)-total
print(ans)

Submission status: Accepted

Solution code:
def function(n, list1):
  total = sum(list1)
  if n >= total:
    return n - total
  else:
    return -1
  
line1 = input().split()
n = int(line1[0])
line2 = input().split()
list1 = [int(i) for i in line2]
print(function(n, list1))

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

Submission status: Accepted

Solution code:

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

sm = sum(arr)

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys

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

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

if sum(A)>N:
    print("-1")
    sys.exit()

print(N-sum(A))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# 22:00 ~

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:
data = list(map(int, input().split()))
# data = list(map(int, "41 2".split()))

N = data[0] # days of summer vacation
M = data[1] # summer assignments

A = 0 # days to do the i-th assignment.

assignments = list(map(int, input().split()))
# assignments = list(map(int, "5 6".split()))

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
a = input().split()

N = int(a[0])


c = input().split()



d = 0
  
for i in c:
  d += int(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()))
for i in range(m):
    n -= a[i]
if n >= 0:
    print(n)
else:
    print(-1)

Submission status: Accepted

Solution code:
a,b = map(int,input().split())
li = []
li = [int(j) for j in input().split()]


c = sum(li)

if c> a:
	print(-1)
else:
	print(a-c)

Submission status: Accepted

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

print(-1 if s > n  else n-s)

Submission status: Accepted

Solution code:
n, m = tuple(int(s) for s in input().split())
arr = list(int(s) for s in input().split())

s = sum(arr)
if s > n:
    print(-1)
else:
    print(n - s)

Submission status: Accepted

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

Submission status: Accepted

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

num = 0
for i in range(0, len(a)):
    num += int(a[i])

target = n - num

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

Submission status: Accepted

Solution code:
x, y = map(int,input().split())
arr = list(map(int, input().split()[:y]))
s = 0
for i in arr:
    s += i
re = x - s
if s > x:
    print(-1)
elif s == x:
    print(0)
else:
    print(re)

Submission status: Accepted

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

vacation_day = n - sum(hw)

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

Submission status: Accepted

Solution code:
# -*- coding UTF-8 -*-
n, m = map(int, input().split())
a = [int(x) for x in input().split()]

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

Submission status: Accepted

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

Submission status: Accepted

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

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


total = 0

for i in range(m):
    total += c[i]

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

Submission status: Accepted

Solution code:
l=[list(map(int,input().split())) for _ in range(2)]
homework=0
for i in range(l[0][1]):
    homework=homework+l[1][i]
free=l[0][0]-homework
if free<0:
    print(-1)
else:
    print(free)

Submission status: Accepted

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

Submission status: Accepted

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

days = sum(As)

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

Submission status: Accepted

Solution code:
def MI(): return map(int, input().split())
def LI(): return list(MI())

if __name__ == "__main__":
    N, M = MI()
    A = sum(LI())
    print(N-A if N >= A else -1)

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
a = list(map(int, input().split()))
res=n - sum(a)
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()))
sam =  sum(int(i) for i in a)
SAM = n-sam
if SAM >=0:
  print(SAM)
else:
  print(-1)

Submission status: Accepted

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