Harryxun/sft_time huggingface dataset:
### BUGGY CODE ###

n = int(input())
a = list(map(int, input().split()))
s1 = []
s2 = []
for i in range(n):
    s1.append(sum(a[:i+1]))
    s2.append(sum(a[:i+1]))
ans1 = 0 #偶数インデックスが正
for i in range(n):
    if i % 2 == 0:
        if s1[i] <= 0:
            x = abs(s1[i]) + 1
            ans1 += x
            for j in range(i, n):
                s1[j] += x
        else:
            continue
    else:
        if s1[i] >= 0:
            x = abs(s1[i]) + 1
            ans1 += x
            for j in range(i,n):
                s1[j] -= x
ans2 = 0 #偶数インデックスが負
for i in range(n):
    if i % 2 == 1:
        if s2[i] <= 0:
            x = abs(s2[i]) + 1
            ans2 += x
            for j in range(i, n):
                s2[j] += x
        else:
            continue
    else:
        if s2[i] >= 0:
            x = abs(s2[i]) + 1
            ans2 += x
            for j in range(i,n):
                s2[j] -= x

print(min(ans1, ans2))

### FIXED CODE ###

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

def f(a, sgn):
    cnt = 0
    s = 0
    for i in range(n):
        s += a[i]
        sgn *= (-1) #判定する符号は交互に変わる
        if s * sgn <= 0: #sgn一致しなければその積は負
            x = s + sgn*(-1)
            s -= x
            cnt += abs(x)
        
    return cnt
ans = min(f(a, 1), f(a, -1))
print(ans)
### BUGGY CODE ###

N = int(input())
X = input()
fn = {0: 0}
fn_keys = {0}

def culc_fn(n, fn, fn_keys):
    if not n in fn_keys:
        popcount = bin(n).count('1')
        tmp = n%popcount
        fn[n] = culc_fn(tmp, fn, fn_keys) + 1
        fn_keys.add(n)
    return fn[n]

culc_fn(int('1'*N), fn, fn_keys)

for i in range(N):
    tmp = int(X[:i] + ('0' if X[i] == '1' else '1') + X[i+1:], 2)
    popcount = bin(tmp).count('1')
    if popcount > 0:
        print(culc_fn(tmp%popcount, fn, fn_keys)+1)
    else:
        print(0)

### FIXED CODE ###

# N = 10
# X = '1'*N
N = int(input())
X = input()
popcount_X = X.count('1')
X_ = int(X, 2)

X_mod_minus = X_%(popcount_X-1) if popcount_X > 1 else -1
X_mod_plus = X_%(popcount_X+1)
for i in range(N):
    if X[i] == '0':
        popcount = popcount_X+1
        X_i = (X_mod_plus + pow(2, N-i-1, popcount))%(popcount)
    else:
        if X_mod_minus == -1:
            print(0)
            continue
        popcount = popcount_X-1
        X_i = (X_mod_minus - pow(2, N-i-1, popcount))%(popcount)
    ans = 1
    while X_i > 0:
        X_i %= bin(X_i).count('1')
        ans += 1
    print(ans)
### BUGGY CODE ###

class Hash:
    def __init__(self):
        self.size = 1046527
        self.l = [0] * self.size

    def insert_key(self, st):
        i = 0
        while True:
            j = self.h(st, i)
            if self.l[j] == 0:
                self.l[j] = st
                #print("inserted")
                return
            else:
                i = i+1

    def find_key(self, st):
        i = 0
        while True:
            j = self.h(st, i)
            if self.l[j] == st:
                return "yes"
            elif self.l[j] == 0 or (i >= self.size):
                return "no"
            else:
                i += 1

    def h1(self, key):
        return sum([ord(c) for c in key]) % self.size

    def h2(self, key):
        return 1 + sum([ord(c) for c in key]) % ( self.size - 1 )

    def h (self, key, i):
        return (self.h1(key) + i* self.h2(key)) % self.size

#main
n = int(input())
hash = Hash()

for _ in range(n):
    ope, st = input().split()
    if ope == "insert":
        hash.insert_key(st)
    elif ope == "find":
        print(hash.find_key(st))

### FIXED CODE ###

dic ={}


n = int(input())

for _ in range(n):
    com, word = input().split()
    
    if com =="insert":
        dic[word] = True
    elif com =='find':
        print("yes" if word in dic else "no")
### BUGGY CODE ###

n,k = map(int,input().split())
p = list(map(int,input().split()))
p_ = []
for i in p:
  p_.append(sum(range(i+1))/i)
ans = 0
for i in range(n-k+1):
  ans = max(ans,sum(p_[i:i+k]))
print(ans)
  
  
  
  


### FIXED CODE ###

n,k = map(int,input().split())
p = list(map(int,input().split()))
p_ = [(i+1)/2 for i in p]
d = [0]
for i in p_:
  d.append(d[-1]+i)
ans = 0
for i in range(k,n+1):
  if ans < d[i]-d[i-k]:
    ans = d[i]-d[i-k]
print(ans)
### BUGGY CODE ###

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

for i in range(0,n):
  print (a.count(i+1))
  a= [a[j] for j in range(0, len(a)) if a[j] != i+1]

### FIXED CODE ###

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

#for i in range(0,n):
#  print (a.count(i+1))
#  a= [a[j] for j in range(0, len(a)) if a[j] != i+1]
#
#  print (a)

kekka= [0] * (n+1)
for i in range(0,n-1):
  kekka[a[i]]+=1

for i in range(1,n+1):
  print (kekka[i])
### BUGGY CODE ###

S = list(input())

a = S[0]
c = 1
while len(S) >1:
  if S[1] == a:
    if len(S) >2:
      a = S[1:3]
      S = [a] + S[3:]
      c += 1
    else:
      break
  else: 
    a = S[1]
    S = [a] + S[2:]
    c += 1
    
print(c)  

### FIXED CODE ###

ss = input()

n = len(ss)
arrs = [ss[0]]

for i in range(1, n):
    if len(arrs[-1]) == 2:
        if arrs[-1].endswith(ss[i]):
            arrs.append('*')
        else:
            arrs.append(ss[i])

    else:
        if arrs[-1] == ss[i]:
            arrs.append(ss[i: i + 2])
        else:
            arrs.append(ss[i])

c = arrs.count('*')

if arrs[-1] == arrs[-2]:
    ans = len(arrs) - 1

else:
    ans = len(arrs)
print(ans - c)
### BUGGY CODE ###

n = int(input())
lis = list(map(int,input().split()))
 
k = [1+lis.index(l) for l in range(1,n+1)]
 
print(*k)


### FIXED CODE ###

n = int(input())
lis = list(map(int, input().split()))
a = [0]*n

for i, item in enumerate(lis):
    a[item - 1] = i + 1

print(*a)
### BUGGY CODE ###

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

scores = []

score = 1
for i in range(k-1, -1, -1):
    score *= a[i]

scores.append(score)

for j in range(k, n):
    scores.append(scores[-1] * a[j] / a[j-k])
    if scores[-1] > scores[-2]:
        print('Yes')
    else:
        print('No')

### FIXED CODE ###

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

for i in range(k, n):
    if a[i] > a[i-k]:
        print('Yes')
    else:
        print('No')
### BUGGY CODE ###

mod = 998244353
n, s = map(int, input().split())
dp = [[0] * (s + 1) for _ in range(n + 1)]
dp[0][0] = 1
for i, a in enumerate(map(int, input().split())):
  for j in range(s + 1):
    dp[i+1][j] = (dp[i][j] * 2) % mod
    if j >= a:
      dp[i+1][j] = (dp[i+1][j] + dp[i][j-a]) % mod
print(dp[-1][-1])

### FIXED CODE ###

import numpy as np

mod = 998244353
n, s = map(int, input().split())
dp = np.zeros((n+1, s+1), dtype=int)
dp[0, 0] = 1
for i, a in enumerate(map(int, input().split())):
  dp[i+1] = dp[i] * 2 % mod
  dp[i+1][a:] = (dp[i+1][a:] + dp[i][:-a]) % mod
print(dp[-1, -1])
### BUGGY CODE ###

import sys
n = int(input())
a = list(map(int, input().split()))
postCenter=dif=0
tmp = sys.maxsize
for i in range(n):
    if tmp > abs(sum(a[:i])-sum(a[i:])):
        tmp = abs(sum(a[:i])-sum(a[i:]))
print(int(tmp))

### FIXED CODE ###

import sys
n = int(input())
a = list(map(int, input().split()))
tmp=sys.maxsize
s = sum(a)
t = 0
for i in range(n):
    t += a[i]
    tmp = min(tmp,abs(s-t*2))
print(tmp)
### BUGGY CODE ###

import sys
sys.setrecursionlimit(10000000)
input=sys.stdin.readline

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

a=10**18
ans=1
for i in l:
    ans*=i

if ans > a:print(-1);exit()
print(ans)

### FIXED CODE ###

import sys
sys.setrecursionlimit(10000000)
input=sys.stdin.readline
 
n = int(input())
l = list(map(int,input().split()))

if 0 in l:print(0);exit()

a=10**18
ans=1
for i in l:
    ans*=i
    if ans > a:print(-1);exit()

print(ans)
### BUGGY CODE ###

n, m = map(int, input().split())
a = list(map(int, input().split()))
for i in range(m):
    idx = a.index(max(a))
    a[idx] = a[idx]//2
print(sum(a))

### FIXED CODE ###

import heapq
n, m = map(int, input().split())
a = list(map(lambda x: int(x)*(-1), input().split()))
heapq.heapify(a)
for _ in range(m):
    t = heapq.heappop(a)
    heapq.heappush(a, (-1)*(-t//2))
print(-sum(a))
### BUGGY CODE ###

# -*- coding: utf-8 -*-
# モジュールのインポート
import math
import itertools

# 標準入力を取得
N = int(input())


def has_z(n: int, x: int, y: int, d: int) -> bool:
    if d < 0:
        return False
    z = (-(x + y) + math.sqrt(d)) / 2
    return (z.is_integer()) and (z >= 1)


# 求解処理
D = {}
for n in range(1, N + 1):
    ans = 0
    max_v = int(math.sqrt(n))
    for x in range(1, max_v + 1):
        for y in range(x, max_v + 1):
            if (n, x, y) not in D.keys():
                D[(n, x, y)] = 4 * n - 3 * x ** 2 - 3 * y ** 2 - 2 * x * y
            d = D[(n, x, y)]
            if has_z(n, x, y, d):
                ans += 1 + (x != y)
    print(ans)


### FIXED CODE ###

# -*- coding: utf-8 -*-
# モジュールのインポート
import math
import itertools

# 標準入力を取得
N = int(input())

# メイン処理


def g(x: int, y: int, z: int) -> int:
    return x**2 + y**2 + z**2 + x*y + y*z + z*x


l = [0 for n in range(N)]
for x, y, z in itertools.product(range(1, int(math.sqrt(N)) + 1), repeat=3):
    v = g(x, y, z)
    if v <= N:
        l[v - 1] += 1

# 結果出力
for ans in l:
    print(ans)
### BUGGY CODE ###

def main():
    N = int(input())
    a = [list(map(int, input().split())) for i in range(N)]

    now = [0] * N
    day = 0
    gamed_day = [-1] * N
    while True:
        had_game = False
        all_finish = True
        for i in range(N-1, -1, -1):
            if now[i] < N-1 and gamed_day[i] != day:
                all_finish = False
                want = a[i][now[i]] - 1
                if gamed_day[want] != day:# 今日試合していない
                    if a[want][now[want]] - 1 == i:# 相手の試合相手が自分
                        now[want] += 1
                        now[i] += 1
                        gamed_day[i] = day
                        gamed_day[want] = day
                        had_game = True
                        # print(day+1, i+1, want+1)
        if all_finish:
            if had_game:
                print(day+1)
            else:
                print(day)
            break
        if not had_game:
            print(-1)
            break
        day += 1
    # print(now)

if __name__ == "__main__":
    main()


### FIXED CODE ###

import time
def main():
    N = int(input())
    a = [list(map(int, input().split())) for i in range(N)]
    start = time.time()
    now = [0] * N
    day = 0
    gamed_day = [-1] * N
    finished = 0
    while True:
        if time.time() - start > 1.6:
            print((N*(N-1))//2)
            break
        had_game = False
        all_finish = True
        for i in range(N-1, -1, -1):
            if now[i] < N-1 and gamed_day[i] != day:
                all_finish = False
                want = a[i][now[i]] - 1
                if gamed_day[want] != day:# 今日試合していない
                    if a[want][now[want]] - 1 == i:# 相手の試合相手が自分
                        now[want] += 1
                        now[i] += 1
                        if now[want] >= N-1:
                            finished += 1
                        if now[i] >= N-1:
                            finished += 1
                        gamed_day[i] = day
                        gamed_day[want] = day
                        had_game = True
                        # print(day+1, i+1, want+1)
        if all_finish or finished == N:
            if had_game:
                print(day+1)
            else:
                print(day)
            break
        if not had_game:
            print(-1)
            break
        day += 1
    # print(now)

if __name__ == "__main__":
    main()
### BUGGY CODE ###

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

tmp = 1
for i in range(k):
    tmp *= A[i]

output = []
count = 0
for i in range(k, n):
    if tmp < int(tmp * A[i] / A[count]):
        output.append("Yes")
    else:
        output.append("No")
    tmp = int(tmp * A[i] / A[count])
    count += 1
    
print(*output, sep="\n")

### FIXED CODE ###

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

output = []
count = 0
for i in range(k, n):
    if A[i] > A[count]:
        output.append("Yes")
    else:
        output.append("No")
    count += 1
    
print(*output, sep="\n")
### BUGGY CODE ###

import sys
sys.setrecursionlimit(10**6)
n = int(input())
k = int(input())
def dfs(s, count):
    global ans
    if int(s) > n:
        return
    if count == 0:
        ans += 1
        dfs(s + "0", count)
    else:
        dfs(s + "0", count)
        count -= 1
        for i in range(1, 10):
            dfs(s + str(i), count)
ans = 0
for i in range(1,10):
    dfs(str(i), k-1)
print(ans)

### FIXED CODE ###

s = input()
k = int(input())
l = len(s)
dp = [[[0 for i in range(k+1)] for j in range(2)] for m in range(l+1)]
dp[0][0][0] = 1
for i in range(l):
    for x in range(k+1):
        if s[i] == "0":
            dp[i+1][0][x] += dp[i][0][x]
        else:
            if x < k:
                dp[i+1][0][x+1] += dp[i][0][x]
            dp[i+1][1][x] += dp[i][0][x]
        for j in range(1, int(s[i])):
            if x < k:
                dp[i+1][1][x+1] += dp[i][0][x]
        dp[i+1][1][x] += dp[i][1][x]
        for j in range(1, 10):
            if x < k:
                dp[i+1][1][x+1] += dp[i][1][x]
print(dp[-1][0][-1] + dp[-1][1][-1])
### BUGGY CODE ###

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

ret = 1
for ai in a:
    ret *= ai

if ret > 10**18:
    print(-1)
else:
    print(ret)

### FIXED CODE ###

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

# import numpy as np
# ret = np.prod(a)

if a.count(0) > 0:
    print(0)
else:
    ret = 1
    for ai in a:
        ret *= ai
        if ret > 10**18:
            print(-1)
            break
    else:
        if ret > 10**18:
            print(-1)
        else:
            print(ret)

    # if ret > 10**18 or ret < 0:
    #     print(-1)
    # else:
    #     print(ret)
### BUGGY CODE ###

def main():
    N, M = map(int, input().split())
    for i in range(M):
        if N + i > M:
            break
        if M % (N + i) == 0:
            print(M // (N + i))
            exit()


if __name__ == "__main__":
    main()

### FIXED CODE ###

def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    # divisors.sort()
    return divisors

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

    div = make_divisors(M)
    sort_div = sorted(div)

    ans = 0
    for a in sort_div:
        if a <= M // N:
            ans = a
        else:
            break

    print(ans)


main()
### BUGGY CODE ###

n = int(input())
S = input()
q = int(input())


class BIT:
    def __init__(self, n):
        """
        初期化
        Input:　
            n: 配列の大きさ
        """
        self.n = n
        self.bit = [0] * (n+10)

    def add(self, x, w):
        """
        更新クエリ(add)
        Input:
            x: インデックス
            w: 加える値
        Note:
            self.bitが更新される
        """        
        while x <= self.n:
            self.bit[x] += w
            x += x&-x
    
    def sum(self, x):
        """
        部分和算出クエリ
        Input:
            x: インデックス
        Return:
            [1,a]の部分和
        """
        cnt = 0
        while x > 0:
            cnt += self.bit[x]
            # 次の最下位桁はどこか
            x -= x&-x
        return cnt   
    
    def psum(self, a, b):
        """
        区間[a,b)(0-indexed)における和
        Input
            a,b: 半開区間
        Return
            [a,b)の和
        """
        return self.sum(b-1) - self.sum(a-1)


def str2num(s):
    return ord(s)-ord("a")

bits = [BIT(n) for i in range(26)]
# 入力
ans = []
for i, s in enumerate(S):
    ind = str2num(s)
    bits[ind].add(i+1, 1)

S = list(S)
for _ in range(q):
    x,a,b = input().split()
    if x == "1":
        i = int(a)
        # 更新処理
        ind_before = str2num(S[i-1])
        ind = str2num(b)
        bits[ind_before].add(i,-1)
        bits[ind].add(i, 1)
        S[i-1] = b
    else:
        l = int(a)
        r = int(b)
        cnt = 0
        for bit in bits:
            if bit.psum(l,r+1) > 0:
                cnt += 1
        ans.append(cnt)
print(*ans)

        


### FIXED CODE ###

n = int(input())
S = input()
q = int(input())


class BIT:
    def __init__(self, n):
        """
        初期化
        Input:　
            n: 配列の大きさ
        """
        self.n = n
        self.bit = [0] * (n+10)

    def add(self, x, w):
        """
        更新クエリ(add)
        Input:
            x: インデックス
            w: 加える値
        Note:
            self.bitが更新される
        """        
        while x <= self.n:
            self.bit[x] += w
            x += x&-x
    
    def sum(self, x):
        """
        部分和算出クエリ
        Input:
            x: インデックス
        Return:
            [1,a]の部分和
        """
        cnt = 0
        while x > 0:
            cnt += self.bit[x]
            # 次の最下位桁はどこか
            x -= x&-x
        return cnt   
    
    def psum(self, a, b):
        """
        区間[a,b)(0-indexed)における和
        Input
            a,b: 半開区間
        Return
            [a,b)の和
        """
        return self.sum(b-1) - self.sum(a-1)


def str2num(s):
    return ord(s)-ord("a")

bits = [BIT(n) for i in range(26)]
# 入力
ans = []
for i, s in enumerate(S):
    ind = str2num(s)
    bits[ind].add(i+1, 1)

S = list(S)
for _ in range(q):
    x,a,b = input().split()
    if x == "1":
        i = int(a)
        # 更新処理
        ind_before = str2num(S[i-1])
        ind = str2num(b)
        bits[ind_before].add(i,-1)
        bits[ind].add(i, 1)
        S[i-1] = b
    else:
        l = int(a)
        r = int(b)
        cnt = 0
        for bit in bits:
            if bit.psum(l,r+1) > 0:
                cnt += 1
        ans.append(cnt)
print(*ans)
### BUGGY CODE ###

import itertools

N = int(input())
S = [int(input()) for _ in range(N)]
ans = 0

for i in range(N+1):
  c = itertools.combinations(S, i)
  for s in c:
    sn = list(s)
    if sum(sn) % 10 != 0:
      ans = max(ans, sum(sn))
      
print(ans)

### FIXED CODE ###

import itertools

N = int(input())
S = [int(input()) for _ in range(N)]
ans = 0

for i in range(N-1,N+1):
  c = itertools.combinations(S, i)
  for s in c:
    sn = list(s)
    if sum(sn) % 10 != 0:
      ans = max(ans, sum(sn))
      
print(ans)
### BUGGY CODE ###

h,w,a,b = map(int,input().split())

res = []
for i in range(0,h):
    res.append([0 for i in range(w)])

for i in range(0,w):
    res[0][i] = 1

for j in range(1,h):
    res[j][0] = 1

for i in range(h-a,h):
    for j in range(0,b):
        res[i][j] = -1

for i in range(1,h):
    for j in range(1,w):
        if res[i][j] == -1:
            continue
        elif res[i][j-1] == -1:
            res[i][j] = res[i-1][j]
        else:
            res[i][j] = res[i-1][j] + res[i][j-1]
            if res[i][j] > 10**9+7:
                res[i][j] %= 10**9+7

print(res[h-1][w-1])

### FIXED CODE ###

h, w, a, b = map(int, input().split())
res = 0
kai = min(w - b, h - a)
mod = 10 ** 9 + 7

kaijo = [0] * (h + w + 1)
kaijo[0] = 1
for i in range(1, h + w + 1):
    kaijo[i] = (kaijo[i - 1] * i) % mod
gyaku = [0] * (h + w + 1)
gyaku[h + w] = pow(kaijo[h + w], mod - 2, mod)
for i in range(h + w, 0, -1):
    gyaku[i - 1] = (gyaku[i] * i) % mod


def conb(x, k):
    return (kaijo[x] * gyaku[k] * gyaku[x - k]) % mod


conb1 = conb(h - a - 1 + b, b)
conb2 = conb(a + w - b - 1, a)
combi = conb1 * conb2
res = combi

for i in range(1, kai):
    res += conb(h - a - 1 + b, b + i) * conb(a + w - b - 1, a + i)

res %= mod
print(int(res))
### BUGGY CODE ###

def main():
    from bisect import bisect_left
    n, *abc = map(int, open(0).read().split())
    a, b, c = abc[:n], abc[n:2 * n], abc[2 * n:]
    a, b, c = sorted(a), sorted(b), sorted(c)
    ans = 0
    for i in c:
        j = bisect_left(b, i)
        for k in b[:j]:
            l = bisect_left(a, k)
            ans += l

    print(ans)


if __name__ == '__main__':
    main()


### FIXED CODE ###

def main():
    from bisect import bisect_left, bisect_right
    n, *abc = map(int, open(0).read().split())
    a, b, c = abc[:n], abc[n:2 * n], abc[2 * n:]
    a, b, c = sorted(a), sorted(b), sorted(c)
    ans = 0
    for i in b:
        j = bisect_left(a, i)
        k = n - bisect_right(c, i)
        ans += j * k

    print(ans)


if __name__ == '__main__':
    main()
### BUGGY CODE ###

nm = list(map(int, input().split()))
n = nm[0]
m = nm[1]
a = []
b = []

for i in range(n):
    ab = list(map(int, input().split()))
    a.append(ab[0])
    b.append(ab[1])

money = 0
count = 0

while count < m:
    minimum = min(a)
    money = money + minimum

    num = a.index(minimum)
    b[num] = b[num] - 1
    if b[num] == 0:
        del(b[num])
        del(a[num])
    count = count + 1

print(money)

### FIXED CODE ###

nm = list(map(int, input().split()))
n = nm[0]
m = nm[1]
abs = []

for i in range(n):
    ab = list(map(int, input().split()))
    abs.append(ab)

abs = sorted(abs, key=lambda x: x[0])

money = 0
count = 0

for i in range(n):
    money = money + abs[i][0] * abs[i][1]
    count = count + abs[i][1]
    if count >= m:
        money = money - abs[i][0] * (count - m)
        break

print(money)
### BUGGY CODE ###

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

sei=[1]*2
cou=0
while True:
  if cou==n-k:
    break
  for i in range(cou,cou+k):
    sei[0]*=a[i]
    sei[1]*=a[i+1]
  if sei[0]<sei[1]:
    print("Yes")
    sei=[1]*2
  else:
    print("No")
    sei=[1]*2
  cou+=1



### FIXED CODE ###

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

for i in range(n-k):

  if  a[i]<a[i+k]:
    print("Yes")
  else:
    print("No")
### BUGGY CODE ###

n = int(input())

tmp = [int(s) for s in input().split()]

A = {}
for i in range(n):
    A[i] = tmp[i]

#print(A)
def solve(A,n):
    keys = [k for k, v in A.items() if v == 1]
    
    if(len(keys) == 0):
        print(-1)
        return
    else:
        index = min(keys)
    
    #print(index)
    val = 2
    while True:
        #print(val,index)
        keys = [k for k, v in A.items() if v == val]
        if(len(keys) != 0):
            #print(min(keys))
            tmp = [s for s in keys if(s >= index)]
            if(len(tmp) != 0):
                index = min(tmp)
                val += 1
            else:
                #print("hi")
                val -= 1
                break
        else:
            
            val -= 1
            break
    #print(val,index)
    print(n-val)

solve(A,n) 

### FIXED CODE ###

n = int(input())

tmp = [int(s) for s in input().split()]

target = 1
flag = 0
for i in range(n):
    if(tmp[i] == target):
        flag = 1
        target += 1
#print(target)
if(flag == 0):
    print(-1)
else:
    print(n - target +1)
### BUGGY CODE ###

h,w=map(int,input().split())
a=[list(map(int,input().split()))for i in range(h)]
b=[list(map(int,input().split()))for i in range(h)]
c=[[abs(a[i][j]-b[i][j])for j in range(w)]for i in range(h)]
d=[[set()for i in range(w+1)]for j in range(h+1)]
d[1][1]=set([-c[0][0],c[0][0]])
for x in range(1,h+1):
    for y in range(1,w+1):
        if not (x==1 and y==1):
            a=d[x-1][y]|d[x][y-1]
            for i in a:
                d[x][y].add(i-c[x-1][y-1])
                if i+c[x-1][y-1]<=80*(h+w-x-y+1):
                    d[x][y].add(i+c[x-1][y-1])
print(abs(min(d[h][w],key=abs)))

### FIXED CODE ###

h,w=map(int,input().split())
a=[list(map(int,input().split()))for i in range(h)]
b=[list(map(int,input().split()))for i in range(h)]
s=[0]*w
s[0]=p=1<<6400
for i in range(h):
    for j in range(w):
        d=abs(a[i][j]-b[i][j])
        if j>0:
            s[j]|=s[j-1]
        s[j]=(s[j]<<d)|(s[j]>>d)
t=s[-1]
for i in range(6401):
    if t&(p<<i) or t&(p>>i):
        print(i)
        break