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

# -*- coding: utf-8 -*-
n,c = map(int, input().split())
tv = []
T = 0
for _ in range(n):
    line = list(map(int, input().split()))
    T = max(T, line[1])
    tv.append(line)

rm = [0 for _ in range(2*T)]

for ci in range(c):
    tt = [0 for _ in range(2*T)]
    for i in range(n):
        if tv[i][2]==ci+1:
            tt[2*tv[i][0]-2] += 1
            tt[2*tv[i][1]-1] -= 1
    for t in range(2*T-1):
        tt[t+1] = tt[t+1]+tt[t]
    for t in range(2*T):
        if tt[t]>0:
            rm[t] += 1
    # print(tt)
# print(rm)
ret = 0
for s in rm:
    ret = max(ret, s)
print(ret)


### FIXED CODE ###

# -*- coding: utf-8 -*-
from operator import itemgetter

N,C = map(int, input().split())
record = []
for _ in range(N):
    s,t,c = map(int, input().split())
    record.append((s,t,c))
record.sort(key=itemgetter(1,0,2))

def can_record(k):
    slots = [(-1,-1)]*k  # (end_time, channel)

    for r in record:
        idx = -1
        t = -1
        for i in range(k):
            end_time, channel = slots[i]
            if channel==r[2]:
                if end_time<=r[0]:
                    if t<=end_time:
                        t = end_time
                        idx = i
            else:
                if end_time<r[0]:
                    if t<=end_time:
                        t = end_time
                        idx = i
        if idx==-1:
            return False
        else:
            slots[idx] = (r[1],r[2])
    return True

for k in range(1,C+1):
    if can_record(k):
        print(k)
        break
### BUGGY CODE ###

n = int(input())
a = list(map(int,input().split()))
b = []
x = sum(a)
for i in range(n):
    m = 0
    for j in range(n):
        if i == j:
            pass
        else:
            m = m ^ a[j]
    b.append(m)
b = map(str,b)
print(' '.join(b))

### FIXED CODE ###

import time
start = time.time()
n = int(input())
a = list(map(int,input().split()))
b = []
m = 0
for i in range(1,n):
    m = m ^ a[i]
b.append(m)
for j in range(1,n):
    m = m ^ a[j-1]
    m = m ^ a[j]
    b.append(m)
b = map(str,b)
print(' '.join(b))
### BUGGY CODE ###

n, m = map(int, input().split())
G = [[] for _ in range(n)]
indeg = [0] * n

for _ in range(m):
    l, r, d = map(int, input().split())
    l -= 1
    r -= 1
    G[r].append((l, d))
    indeg[r] += 1

from collections import deque
ng = False
for start, deg in enumerate(indeg):
    if deg == 0:
        continue
    st = deque([[start, 0]])
    visited_cost = [-1] * n
    while st:
        i, cost = st.pop()
        for ni, nd in G[i]:
            if visited_cost[ni] == -1:
                # まだ記録されていない
                visited_cost[ni] = cost + nd
                st.append([ni, cost + nd])
            elif visited_cost[ni] == cost + nd:
                # 既に記録されていて、矛盾していない場合
                # これ以上探索の必要がない
                continue
            else:
                # 既に記録されていて、矛盾している場合
                # 終了
                ng = True
                break
        if ng:
            break
    if ng:
        break

print('No' if ng else 'Yes')


### FIXED CODE ###

n, m = map(int, input().split())
G = [[] for _ in range(n)]
indeg = [0] * n

for _ in range(m):
    l, r, d = map(int, input().split())
    l -= 1
    r -= 1
    G[l].append((r, d))
    G[r].append((l, -d))

from collections import deque
ng = False
visited = [0] * n
visited_cost = [0] * n

for start in range(n):
    if visited[start]:
        continue
    visited[start] = 1
    st = deque([[start, 0]])
    while st:
        i, cost = st.pop()
        for ni, nd in G[i]:
            if visited[ni] == 0:
                visited[ni] = 1
                visited_cost[ni] = cost + nd
                st.append([ni, cost + nd])
            else:
                # 既に記録されていて、矛盾している場合
                if visited_cost[ni] != cost + nd:
                    # 終了
                    ng = True
                    break
        if ng:
            break
    if ng:
        break
print('No' if ng else 'Yes')
### BUGGY CODE ###

def is_prime(n):
    i=1
    while i*i<n:
        if n%i==0:
            return False
        i+=1
    return True 

n=int(input())+1
while not is_prime(n):
    n+=1
print(n)

### FIXED CODE ###

def is_prime(n):
    i=2
    while i*i<n:
        if n%i==0:
            return False
        i+=1
    return True 

n=int(input())
while not is_prime(n):
    n+=1
print(n)
### BUGGY CODE ###

#import numpy as np
#from numpy import*
#from scipy.sparse.csgraph import shortest_path #shortest_path(csgraph=graph) # dijkstra# floyd_warshall
#from scipy.sparse import csr_matrix
 
#from collections import* #defaultdict Counter deque appendleft
#from fractions import gcd
#from functools import* #reduce
#from itertools import* #permutations("AB",repeat=2) combinations("AB",2) product("AB",2) groupby accumulate
#from operator import mul,itemgetter
#from bisect import* #bisect_left bisect_right
#from heapq import* #heapify heappop heappushpop
#from math import factorial,pi
#from copy import deepcopy
#import sys
#sys.setrecursionlimit(10**8)
#input=sys.stdin.readline  #危険！基本オフにしろ！
 
def main():
    MOD=10**9+7
    s="0"+input()
    dp=[[0]*len(s)for i in range(13)]
    dp[0][0]=1
    for k,j in enumerate(s[1:]):
        for i in range(13):
            if dp[i][k]:
                if j=="?":
                    for r in range(10):
                        dp[int(str(i)+str(r))%13][k+1]+=dp[i][k]%MOD
                else:
                    dp[int(str(i)+j)%13][k+1]+=dp[i][k]%MOD
            else:
                continue
    print(dp[5][-1]%MOD)
    
if __name__ == '__main__':
    main()

### FIXED CODE ###

def main():
    MOD=10**9+7
    s="0"+input()
    dp=[[0]*len(s)for i in range(13)]
    dp[0][0]=1
    for k,j in enumerate(s[1:]):
        for i in range(13):
            if dp[i][k]:
                if j=="?":
                    for r in range(10):
                        dp[(10*i+r)%13][k+1]+=dp[i][k]%MOD
                else:
                    dp[int(str(i)+j)%13][k+1]+=dp[i][k]%MOD
    print(dp[5][-1]%MOD)
if __name__ == '__main__':
    main()
### BUGGY CODE ###

import sys


def main():
    S = input()

    MOD = 10**9+7
    dp = [[0]*13 for _ in range(len(S)+1)]
    dp[0][0] = 1

    for i in range(len(S)):
        if S[i] == "?":
            c = -1
        else:
            c = int(S[i])
        for j in range(10):
            if c != -1 and c != j:
                continue
            for ki in range(13):
                dp[i+1][(ki*10+j) % 13] += dp[i][ki]

    print(dp[len(S)][5] % MOD)


if __name__ == "__main__":
    main()


### FIXED CODE ###

S = input()
mod = 10**9+7
dp = [[0]*13 for _ in range(len(S)+1)]
d = 1
dp[0][0] = 1

for i, s in enumerate(S[::-1]):
    if s == "?":
        for j in range(13):
            for k in range(10):
                dp[i+1][(j+(d*k)) % 13] += dp[i][j]
    else:
        for j in range(13):
            dp[i+1][(j+(d*int(s))) % 13] += dp[i][j]
    for j in range(13):
        dp[i+1][j] %= mod
    d = (d*10) % 13
print(dp[-1][5])
### BUGGY CODE ###

K = int(input())

ans = -1
num7 = 7;

for i in range(100000):
    if (num7 % K) == 0:
        ans = i+1
        break
    else:
        num7 = num7*10+7
        i+=1

print(ans)

### FIXED CODE ###

K = int(input())

ans = -1
num7 = 7

for i in range(1000000):
    if (num7 % K) == 0:
        ans = i+1
        break
    else:
        num7 = (num7*10+7)%K
        i+=1

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

N = int(input())
inlist = []
for i in range(N):
  inputst = input()
  inputstlist = list(inputst)
  inputstlist.sort()
  inlist.append(inputstlist)
inlist.sort()
count=0
for i in range(N):
  for j in range(i+1,N):
    flag1=0
    for k in range(10):
      if inlist[i][k]==inlist[j][k]:
        pass
      else:
        flag1=1
        break
    if flag1==0:
      count+=1
    else:
      break
print(count)  

### FIXED CODE ###

N = int(input())
inlist = []
for i in range(N):
  inputst = input()
  inputstlist = list(inputst)
  inputstlist.sort()
  inlist.append(inputstlist)
inlist.sort()
count=0
i=0
while i<N:
  skip=0
  for j in range(i+1,N):
    flag1=0
    for k in range(10):
      if inlist[i][k]!=inlist[j][k]:
        flag1=1
        break
    if flag1==0:#一致
      count+=1
      skip+=1
    else:#不一致
      break
  if skip>=1:
    i=i+skip
    count+=int(((skip-1)+1)*(skip-1)/2)
  else:
    i+=1
print(count)
### BUGGY CODE ###

N, K=map(int, input().split())
p=list(map(int, input().split()))

M=0
for i in range(N-K+1):
  M=max(M, sum(p[i:K+i]))

ans=M/2+K/2
print(ans)

### FIXED CODE ###

N, K=map(int, input().split())
p=list(map(int, input().split()))

M=[sum(p[:K])]
for i in range(1,N-K+1):
  tmp=M[-1]-p[i-1]+p[i+K-1]
  M.append(tmp)

ans=max(M)/2+K/2
print(ans)
### BUGGY CODE ###

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

def calc_ex(x):
    return  x/2 + 0.5
p_ = list(map(calc_ex,p_))

cnt,res =0,[]
for i in range(n-k+1):
    cnt = sum(p_[:i+k]) - sum(p_[:i])
    res.append(cnt)

print(max(res))


### FIXED CODE ###

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

def calc_ex(x):
    return  x/2 + 0.5
p_ = list(map(calc_ex,p_))

res = sum(p_[:k])
cnt = sum(p_[:k])
for i in range(1,n-k+1):
    cnt = cnt - p_[i-1] + p_[i+k-1]
    res = max(res,cnt)
print(res)
### BUGGY CODE ###

N = int(input())

A_i = []
for i in range(N):
    A_i.append(int(input()))

A_i_max = max(A_i)

for i in range(N):
    if A_i_max == A_i[i] and A_i.count(A_i[i]) == 1:
        A_i_copy = A_i[:]
        A_i_copy.pop(i)
        print(max(A_i_copy))
    else:
        print(A_i_max)

### FIXED CODE ###

N = int(input())

A_i = []
for i in range(N):
    A_i.append(int(input()))

A_i_sord = sorted(A_i)
A_i_max_first = A_i_sord[N - 1]
A_i_max_second = A_i_sord[N - 2]

for i in range(N):
    if A_i_max_first == A_i[i]:
        print(A_i_max_second)
    else:
        print(A_i_max_first)
### BUGGY CODE ###

import numpy as np

n,q = map(int,input().split())
s = input()
lr = [list(map(int,input().split())) for _ in range(q)]
ac_l = []
for i in range(n-1):
    if s[i:i+2] == "AC":ac_l.append(i+1)
ac = np.array(ac_l)

for i in range(q):
    print(np.sum(lr[i][0] <= ac) - np.sum(lr[i][1] <= ac))

### FIXED CODE ###

n,q = map(int,input().split())
s = input().replace("AC","aC")
L = [0]*n
cnt = 0
for i in range(1,n):
    if s[i-1] == "a":
        cnt += 1
    L[i]=cnt
        
for i in range(q):
    l,r = map(int,input().split())
    print(L[r-1] - L[l-1])
### BUGGY CODE ###

import numpy as np

n, k = map(int, input().split())
a = list(map(lambda x: int(x) - 1, input().split()))

table = np.zeros((64, n), dtype=np.int64)
table[0] = a

for i in range(61):
    for j in range(n):
        table[i + 1][j] = table[i][table[i][j]]

ans = 0
for i in range(61, -1, -1):
    if k >> i & 1:
        ans = table[i][ans]
print(ans + 1)


### FIXED CODE ###

n, k = map(int, input().split())
a = list(map(lambda x: int(x) - 1, input().split()))

table = [[0] * n for _ in [0] * 64]
table[0] = a

for i in range(61):
    for j in range(n):
        table[i + 1][j] = table[i][table[i][j]]

ans = 0
for i in range(61, -1, -1):
    if k >> i & 1:
        ans = table[i][ans]
print(ans + 1)
### BUGGY CODE ###

#i文字目を見て，それより前のAの個数，ABの個数，ABCの個数を持っておく

S=input()
N=len(S)
dp=[0,0,0]

mod=10**9+7

p=[1]*(N+1)
for i in range(N):
    p[i+1]=p[i]*3


count=0#?の数
for i in range(N):
    if S[i]=="A":
        dp[0]+=p[count]
    elif S[i]=="B":
        dp[1]+=dp[0]
    elif S[i]=="C":
        dp[2]+=dp[1]
    else:
        dp[2]=dp[2]*3+dp[1]
        dp[1]=dp[1]*3+dp[0]
        dp[0]=dp[0]*3+p[count]
        count+=1
        
print(dp[-1]%mod)   







### FIXED CODE ###

#i文字目を見て，それより前のAの個数，ABの個数，ABCの個数を持っておく

S=input()
N=len(S)
dp=[0,0,0]

mod=10**9+7

p=[1]*(N+1)
for i in range(N):
    p[i+1]=(p[i]*3)%mod


count=0#?の数
for i in range(N):
    if S[i]=="A":
        dp[0]=(dp[0]+p[count]) %mod
    elif S[i]=="B":
        dp[1]=(dp[1]+dp[0])%mod
    elif S[i]=="C":
        dp[2]=(dp[2]+dp[1])%mod
    else:
        dp[2]=(dp[2]*3+dp[1])%mod
        dp[1]=(dp[1]*3+dp[0])%mod
        dp[0]=(dp[0]*3+p[count])%mod
        count+=1
        
print(dp[2]%mod)
### BUGGY CODE ###

from operator import itemgetter
n, m = map(int, input().split())
abab = [list(map(int, input().split())) for _ in range(n)]
abab = sorted(sorted(abab, key=itemgetter(0), reverse=True), key=itemgetter(1), reverse=True)

gyara = [0 for _ in range(m+1)]

for a, b in abab :
    for i in range(a, m+1) :
        if gyara[i] == 0 :
            gyara[i] = b
            break

print(sum(gyara))

### FIXED CODE ###

from heapq import *

n, m = map(int, input().split())
abab = [list(map(int, input().split())) for _ in range(n)]
bites = [[] for _ in range(m)]
for a, b in abab :
    if a <= m : bites[a-1].append(-b)
    
ans = 0
board = []
for bite in bites:
    for b in bite : heappush(board, b)
    if board : ans -= heappop(board)
print(ans)
### BUGGY CODE ###

N=int(input())
x=[]
m=N+1
x.append(set([1,N]))
for i in range(2,N):
    if N%i==0:
        a=i
        b=N//i
        m=min(m,a+b)
        if set([a,b]) in x:
            break
        else:
            x.append(set([a,b]))

print(m-2)
 

### FIXED CODE ###

import math
N=int(input())
m=N+1
for j in range(2,int(math.sqrt(N))+1):
    if N%j==0:
        a=j
        b=N//j
        if a>b:
            break
        else:
            m=min(m,(a+b))

print(m-2)
### BUGGY CODE ###

#abc124 c
def func(keta):
    ans1=0
    ans2=0
    for i in range(len(s)):
        if i%2==0:
            ans1+=2**i
        else:
            ans2+=2**i
    return ans1,ans2
s=input()
c1,c2=func(len(s))
s=int(s,2)
cnt1=bin(c1^s).count("1")
cnt2=bin(c2^s).count("1")
ans=min(cnt1,cnt2)
print(ans)

### FIXED CODE ###

#abc124 c
s=input()
ans1=0
ans2=0
for i in range(len(s)):
    if i%2==0:
        if s[i]=="1":
            ans1+=1
        else:
            ans2+=1
    else:
        if s[i]=="0":
            ans1+=1
        else:
            ans2+=1
ans=min(ans1,ans2)
print(ans)
### BUGGY CODE ###

n = int(input())
s = input()
ans = 0
for i in range(1000):
  a = [i//100, (i//10)%10, i%10]
  cnt = 0
  for j in range(n):
    if cnt <= 2 and a[cnt] == int(s[j]): cnt+=1
  if cnt == 3: ans += 1
print(ans)

### FIXED CODE ###

n = int(input())
s = input()
ans = 0
for i in range(1000):
  a = [i//100, (i//10)%10, i%10]
  cnt = 0
  for j in range(n):
    if cnt <= 2 and a[cnt] == int(s[j]): cnt+=1
  if cnt == 3: ans += 1
print(ans)
### BUGGY CODE ###

N, M = map(int,input().split())
a=list(map(int,input().split()))
for i in range(M):
	a=sorted(a)
	b, c = map(int,input().split())
	for j in range(b):
		if a[j] > c:
			break
		else:
			a[j] = c
print(sum(a))

### FIXED CODE ###

N, M = map(int,input().split())
a = list(map(int,input().split()))
check = []
for i in range(M):
    check.append(list(map(int,input().split())))
check.sort(key=lambda x : x[1],reverse = True)
a.sort()
ans = []
for b, c in check:
    ans += [c for i in range(b)]
    if len(ans) > N:
        break
else:
    ans+=[0 for i in range(N-len(ans))]
A=0
for i in range(N):
    A+=max(ans[i],a[i])
print(A)
### BUGGY CODE ###

S = input()[:: -1]
mod = 10 ** 9 + 7
dp = [[0 for _ in range(13)] for _ in range(len(S) + 1)]

if S[0] == "?":
    for k in range(10):
        dp[1][k % 13] += 1
else:
    dp[1][int(S[0]) % 13] += 1

for i in range(2, len(S) + 1):
    tmp = pow(10, i - 1, 13)
    for j in range(13):
        if S[i - 1] == "?":
            for k in range(10):
                dp[i][(tmp * k + j) % 13] += dp[i - 1][j] % mod
        else:
            dp[i][(tmp * int(S[i - 1]) + j) % 13] += dp[i - 1][j] % mod

print(dp[len(S)][5] % mod)

### FIXED CODE ###

S = input()[:: -1]
mod = 10 ** 9 + 7
dp = [[0 for _ in range(13)] for _ in range(len(S) + 1)]

if S[0] == "?":
    for k in range(10):
        dp[1][k % 13] += 1
else:
    dp[1][int(S[0]) % 13] += 1

tmp = 1
for i in range(2, len(S) + 1):
    tmp *= 10
    tmp %= 13
    for j in range(13):
        if dp[i - 1][j] > 0:
            if S[i - 1] == "?":
                for k in range(10):
                    dp[i][(tmp * k + j) % 13] += dp[i - 1][j] % mod
            else:
                dp[i][(tmp * int(S[i - 1]) + j) % 13] += dp[i - 1][j] % mod

print(dp[len(S)][5] % mod)
### BUGGY CODE ###

N, K = map(int, input().split())
A = list(map(int, input().split()))
F = list(map(int, input().split()))
def check(tmp):
    k = 0
    for x, y in zip(A, F):
        if x*y > tmp:
            k += x - (tmp // y)
        #k += max(0, x - (tmp // y))
    return(K >= k)
A.sort()
F.sort(reverse=True)
r = A[-1]*F[0]
l = -1
while(r-l > 1):
    tmp = (l+r)//2
    if check(tmp):
        r = tmp
    else:
        l = tmp
print(r)


### FIXED CODE ###

import sys
import bisect
import math
input = sys.stdin.readline
N, K = map(int, input().split())
A = list(map(int, input().split()))
F = list(map(int, input().split()))

A.sort()
F.sort(reverse=True)

B = [(A[i]*F[i], F[i]) for i in range(N)]
B.sort(reverse=True)
L = 0
R = B[0][0]
if sum(A) <= K:
    print(0)
    exit(0)
while(1):
    ans = (L+R) // 2
    flag = True
    tmp = 0
    for i in range(N):
        tmp += math.ceil(max(B[i][0] - ans, 0) / B[i][1])
        if tmp > K:
            flag = False
            break
    if flag:
        R = ans
    else:
        L = ans
    if L == R or L+1 == R:
        print(R)
        break
### BUGGY CODE ###

n=int(input())
a=[]
for i in range(1,n+1):
    if n%i==0:
        a.append(n//i+i-2)
print(a[len(a)//2-1])

### FIXED CODE ###

n=int(input())
i=0
s=[]
p=0
for i in range(int(n**0.5)):
    i+=1
    if n%i==0:
        p=1
        s.append(n//i+i-2)
print(min(s))
### BUGGY CODE ###

def main():
    class unionfind():
        def __init__(self,n):
            self.par = [i for i in range(n)]
            self.size = [1 for i in range(n)]

        def root(self,x):
            if self.par[x] == x:
                return x
            else:
                self.par[x] = self.root(self.par[x])
                return self.par[x]

        def same(self,x,y):
            return self.root(x) == self.root(y)

        def unite(self,x,y):
            x = self.root(x)
            y = self.root(y)
            if x!=y:
                self.par[y] = x
                self.size[x] +=self.size[y]
        def get_size(self,x):
            x = self.root(x)
            return self.size[x]

    import sys
    sys.setrecursionlimit(10**6)
    input = sys.stdin.readline
    n,m,k = map(int,input().split())
    uff = unionfind(n)
    fr = [0 for i in range(n)]


    for i in range(m):
        a,b = map(lambda x:int(x)-1,input().split())
        uff.unite(a,b)
        fr[a]+=1
        fr[b]+=1


    ans = [uff.get_size(i) -fr[i]-1 for i in range(n)]

    for i in range(k):
        c,d = map(lambda x:int(x)-1,input().split())
        if uff.same(c,d):
            ans[c] -=1
            ans[d] -=1
    print(*ans)
if __name__=="__main__":
    main()


### FIXED CODE ###


def main():
    class UnionFind():
        def __init__(self, n):
            self.n = n
            self.parents = [-1] * n

        def find(self, x):
            if self.parents[x] < 0:
                return x
            else:
                self.parents[x] = self.find(self.parents[x])
                return self.parents[x]

        def union(self, x, y):
            x = self.find(x)
            y = self.find(y)

            if x == y:
                return

            if self.parents[x] > self.parents[y]:
                x, y = y, x

            self.parents[x] += self.parents[y]
            self.parents[y] = x

        def size(self, x):
            return -self.parents[self.find(x)]

        def same(self, x, y):
            return self.find(x) == self.find(y)

        def members(self, x):
            root = self.find(x)
            return [i for i in range(self.n) if self.find(i) == root]

        def roots(self):
            return [i for i, x in enumerate(self.parents) if x < 0]

        def group_count(self):
            return len(self.roots())

        def all_group_members(self):
            return {r: self.members(r) for r in self.roots()}

    import sys
    sys.setrecursionlimit(10**6)
    input = sys.stdin.readline
    n,m,k = map(int,input().split())
    uff = UnionFind(n)
    fr = [0]*n

    for i in range(m):
        a,b = map(int,input().split())
        uff.union(a-1,b-1)
        fr[a-1]+=1
        fr[b-1]+=1


    ans = [uff.size(i) -fr[i]-1 for i in range(n)]

    for i in range(k):
        c,d = map(int,input().split())
        if uff.same(c-1,d-1):
            ans[c-1] -=1
            ans[d-1] -=1
    print(*ans)
if __name__=="__main__":
    main()
### BUGGY CODE ###

read = input
A = list(map(int, read().split()))
n = A[-1]
A = A[:3]
A.sort() # ascending
ans = 0
# print(A)
for i in range(n+1):
    for j in range(n+1):
        tmp = A[0]*i + A[1] * j
        if tmp > n:break
        tmp = n - tmp
        if tmp % A[2] == 0:
#             print(i, j, tmp//A[2])
            ans += 1
print(ans)

### FIXED CODE ###

read = input
A = list(map(int, read().split()))
n = A[-1]
A = A[:3]
A.sort(reverse=True) # descending
ans = 0
if A[1] == A[2] and A[1] == 1: #deal with 1 1
    for i in range(n+1):
        tmp = i*A[0]
        if tmp > n:break
#         print(ans, i, A)
        ans += (n-tmp) - 0 + 1
else :
    for i in range(n+1):
        for j in range(n+1):
            tmp = i * A[0] + j * A[1]
            if tmp > n:break
            tmp = n - tmp
            if tmp % A[2] == 0:
    #             print(i, j, tmp//A[2])
                ans += 1
print(ans)
### BUGGY CODE ###

n,q = map(int,input().split())
#s=list(input())	
s = input()



for i in range(q):
    l,r = map(int,input().split())
    s2 = s[l-1:r]
    a = s2.count("AC")
    print(a)



### FIXED CODE ###

n,q = map(int,input().split())
#s=list(input())	
s = input()
index = -1
indexes = []
while True:
    index = s.find("AC", index + 1)
    if index == -1:
        break
    indexes.append(index)
dp = []

for i in range (n):
    dp.append(len(indexes))
    if len(indexes)> 0 and indexes[0] == i:
        indexes.pop(0)
for i in range(q):
    l,r = map(int,input().split())
    print(dp[l-1] - dp[r-1])
### BUGGY CODE ###

def main():
    N, Q = map(int, input().split())
    S = input()
    S_sum = [0] * (N+1)
    for i in range(1,N+1):
        S_sum[i] = S[:i].count('AC')

    for _ in range(Q):
        l, r = map(int, input().split())
        print(S_sum[r]-S_sum[l])


main()

### FIXED CODE ###

def main():
    N, Q = map(int, input().split())
    S = input()
    S_sum = [0] * (N+1)
    for i in range(N):
        S_sum[i+1] = S_sum[i] + (1 if S[i:i+2] == 'AC' else 0)

    for _ in range(Q):
        l, r = map(int, input().split())
        print(S_sum[r-1]-S_sum[l-1])


main()
### BUGGY CODE ###

N,Q=map(int,input().split())
S=input()
l,r=[],[]
for i in range(Q):
    l0,r0=map(int,input().split())
    l.append(l0)
    r.append(r0)
c=[]
for i in range(N):
    c.append(0)
for i in range(N-1):
    if (S[i]=='A') and (S[i+1]=='C'):
        c[i]+=1
for i in range(Q):
    d=c[l[i]-1:r[i]-1]
    print(d.count(1))

### FIXED CODE ###

N,Q=map(int,input().split())
S=input()
t=[0]*N
for i in range(N-1):
    t[i+1]=t[i]+(1 if S[i:i+2]=='AC' else 0)
for i in range(Q):
    l,r=map(int,input().split())
    print(t[r-1]-t[l-1])
### BUGGY CODE ###

import sys
n = int(input())
lis = list(map(int, input().split()))
# print(li)
start_index = 0
has_found_number = 0
for i in range(1,n+1):
    if i in lis:
        lis = lis[lis.index(i):]
        has_found_number = i
        continue
    else:
        break
if has_found_number == 0:
    print(-1)
else:
    print(n-has_found_number)


### FIXED CODE ###

n = int(input())
lis = list(map(int, input().split()))
search_target = 1
founded = 0
for li in lis:
    #search_target = 1
    if li == search_target:
        search_target += 1
        founded = li
        continue
    else:
        continue
if founded == 0:
    print(-1)
else:
    print(n-founded)