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

H, W = map(int, input().split())
m = ['X' + input() + 'X' for i in range(H)]
m.insert(0, 'X' * (W+2))
m.insert(H+1, 'X' * (W+2))
 
cnt = 0
while(True):
  flag = True
  mm = [['X' for i in range(W+2)] for j in range(H+2)]
  for i in range(1, 1+H):
    for j in range(1, 1+W):
      if m[i][j] == '.':
        if m[i+1][j] == '#' or m[i-1][j] == '#' or m[i][j+1] == '#' or m[i][j-1] == '#':
          mm[i][j] = '#'
        else:
          mm[i][j] = '.'
        if flag:
          flag = False
      elif m[i][j] == '#':
        mm[i][j] = '#'
  cnt += 1
  m = mm
  if flag:
    break
 
print(cnt-1)

### FIXED CODE ###

from collections import deque

H, W = map(int, input().split())

m = [['X'] * (W+2)]
for i in range(H):
  row = [c for c in input()]
  row.insert(0, 'X')
  row.append('X')
  m.append(row)
m.append(['X'] * (W+2))

q = deque([deque([(i, j) for j in range(1, 1+W) for i in range(1, 1+H) if m[i][j] == '#'])])

cnt = 0
while(True):
  if not q:
    break
  tt = q.popleft()
  nn = deque([])
  for t in tt:
    # left, right, up, down
    for n in ((t[0]-1, t[1]), (t[0]+1, t[1]), (t[0], t[1]-1), (t[0], t[1]+1)):
      if m[n[0]][n[1]] == '.':
        nn.append(n)
        m[n[0]][n[1]] = '#'
  if nn:
    q.append(nn)
  cnt += 1

print(cnt-1)
### BUGGY CODE ###

MOD = 998244353

N = int(input())
A = [int(input()) for _ in range(N)]
SUM = sum(A)

dp = [ [0] * (SUM + 1) for _ in range(N+1) ]
dp2 = [ [0] * (SUM + 1) for _ in range(N+1) ]
# red [i][r] : rまで塗った
dp[0][0] = 1
dp2[0][0] = 1
for i in range(N):
    a = A[i]
    for r in range(0, SUM-a +1):
        #pick
        dp[i+1][r+a] = ( dp[i+1][r+a] + dp[i][r] ) % MOD
        dp2[i+1][r+a] = ( dp2[i+1][r+a] + dp2[i][r] ) % MOD


    for r in range(0, SUM + 1):
        # nopick    
        # B,G に入れる 2通り考える
        dp[i+1][r] = (dp[i+1][r] +  dp[i][r] * 2 ) % MOD
        dp2[i+1][r] = (dp2[i+1][r] +  dp2[i][r]  ) % MOD

if SUM % 2 ==0:
    notans = sum(dp[N][ SUM//2 : ]) * 3 % MOD

    notans = ( notans - 3 * dp2[N][SUM//2] ) %MOD
    cand = pow(3, N, MOD)

    print(  (cand - notans + MOD) % MOD  )
else:
    notans = sum(dp[N][ SUM//2 + 1: ]) * 3 % MOD
    cand = pow(3, N, MOD)
    print(  (cand - notans + MOD) % MOD  )



### FIXED CODE ###

MOD = 998244353

N = int(input())
A = [int(input()) for _ in range(N)]
SUM = sum(A)

dp = [ [0] * (SUM + 1) for _ in range(N+1) ]
dp2 = [ [0] * (SUM + 1) for _ in range(N+1) ]
# red [i][r] : rまで塗った
dp[0][0] = 1
dp2[0][0] = 1
for i in range(N):
    a = A[i]
    for r in range(0, SUM-a +1):
        #pick
        dp[i+1][r+a] = ( dp[i+1][r+a] + dp[i][r] ) % MOD
        dp2[i+1][r+a] = ( dp2[i+1][r+a] + dp2[i][r] ) % MOD


    for r in range(0, SUM + 1):
        # nopick    
        # B,G に入れる 2通り考える
        dp[i+1][r] = (dp[i+1][r] +  dp[i][r] * 2 ) % MOD
        dp2[i+1][r] = (dp2[i+1][r] +  dp2[i][r]  ) % MOD

if SUM % 2 ==0:
    notans = sum(dp[N][ SUM//2 : ]) * 3 % MOD

    notans = ( notans - 3 * dp2[N][SUM//2] ) %MOD
    cand = pow(3, N, MOD)

    print(  (cand - notans + MOD) % MOD  )
else:
    notans = sum(dp[N][ SUM//2 + 1: ]) * 3 % MOD
    cand = pow(3, N, MOD)
    print(  (cand - notans + MOD) % MOD  )
### BUGGY CODE ###

import random
from collections import defaultdict
from itertools import accumulate
n = int(input())
s = input()
mod = (1<<61)-1
base = 1000+random.randint(0,100)
power = [1]
for i in range(1,n):
	power.append((power[-1]*base)%mod)
hvalue = [0]
for i in range(n):
	hvalue.append((hvalue[-1]+(ord(s[i])*power[i]))%mod)
def rollinghash(l,r):
	return ((hvalue[r]-hvalue[l])*power[n-r])%mod
ans = 0
for i in range(n//2,0,-1):
	dc = defaultdict(int)
	for j in range(n-i+1):
		x = rollinghash(j,i+j)
		if dc[x]:
			rg = dc[x]
			if rg<=j:
				ans = max(ans,i)
				break
		else:
			dc[x] = i+j
	else:
		continue
	break
print(ans)

### FIXED CODE ###

import random
from collections import defaultdict
from itertools import accumulate
import sys
input = sys.stdin.readline
n = int(input())
s = input().rstrip()
mod = (1<<61)-1
base = 1000+random.randint(0,100)
power = [1]
for i in range(1,n):
  power.append((power[-1]*base)%mod)
hvalue = [0]
for i in range(n):
  hvalue.append((hvalue[-1]+(ord(s[i])*power[i]))%mod)
def rollinghash(l,r):
  return ((hvalue[r]-hvalue[l])*power[n-r])%mod
def pun(i):
  dc = defaultdict(int)
  if i>n//2:
    return False
  for j in range(n-i+1):
    x = rollinghash(j,i+j)
    if dc[x]:
      rg =dc[x]
      if rg<=j:
        return True
    else:
      dc[x] = i+j
  return False
l=0
r=n//2+1
while l+1<r:
  mi=(l+r)//2
  if pun(mi):
    l=mi
  else:
    r=mi
print(l)
### BUGGY CODE ###

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

for i in range(q):
    first, last = map(int, input().split())
    print(s.count("AC", first - 1, last))


### FIXED CODE ###

n, q = map(int, input().split())
s = input()
# table = [0] * 100005
table = [0] * n
for i in range(1, n):
    table[i] = table[i - 1]
    if s[i] == "C" and s[i - 1] == "A":
        table[i] += 1

for i in range(q):
    first, last = map(int, input().split())
    print(table[last - 1] - table[first - 1])
### BUGGY CODE ###

a,b,x=map(int,input().split())
s=0
for i in range(b+1):
    if (i>=a) and (i%x==0):
        s+=1
print(s)
        

### FIXED CODE ###

a,b,x=map(int,input().split())
if a==0:
    s=b//x+1
else:
    s=b//x-(a-1)//x
print(s)
### BUGGY CODE ###

n, k = map(int, input().split())
p = list(map(int, input().split()))
p = [_p-1 for _p in p]
c = list(map(int, input().split()))

ans = -float('inf')

visited = [False] * n
ss = []
for i in range(n):
    if visited[i]: continue
    cur = i
    s = []
    while not visited[cur]:
        visited[cur] = True
        s.append(c[cur])
        cur = p[cur]
    ss.append(s)

for s in ss:
    m = len(s)
    cumsum = [0] * (m*2+1)
    for i in range(2*m):
        cumsum[i+1] = cumsum[i] + s[i%m]
    
    amari = [-float('inf')] * m
    for i in range(m):
        for j in range(m):
            amari[j] = max(amari[j], cumsum[i+j] - cumsum[i])
    
    for r in range(0, m):
        if r > k: continue
        q = (k-r)//m
        if r==0 and q==0:
            continue
        
        if cumsum[m] > 0:
            ans = max(ans, amari[r] + cumsum[m]*q)
        elif r > 0:
            ans = max(ans, amari[r])

print(ans)


### FIXED CODE ###

n, k = map(int, input().split())
p = list(map(int, input().split()))
p = [_p-1 for _p in p]
c = list(map(int, input().split()))

ans = -float('inf')

visited = [False] * n
ss = []
for i in range(n):
    if visited[i]: continue
    cur = i
    s = []
    while not visited[cur]:
        visited[cur] = True
        s.append(c[cur])
        cur = p[cur]
    ss.append(s)

for s in ss:
    m = len(s)
    cumsum = [0] * (m*2+1)
    for i in range(2*m):
        cumsum[i+1] = cumsum[i] + s[i%m]
    
    amari = [-float('inf')] * m
    for i in range(m):
        for j in range(m):
            amari[j] = max(amari[j], cumsum[i+j] - cumsum[i])
    
    for r in range(0, m):
        if r > k: continue
        q = (k-r)//m
        if r==0 and q==0:
            continue
        
        if cumsum[m] > 0:
            ans = max(ans, amari[r] + cumsum[m]*q)
        elif r > 0:
            ans = max(ans, amari[r])

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

input()
a=list(map(int,input().split()))
c=i=0
while i < len(a):
	if a[i] != i+1:
		a.pop(i)
		c+=1
		continue
	i+=1
print(c if len(a) else"-1")

### FIXED CODE ###

n=int(input())
a=map(int,input().split())
c=0
i=1
for m in a:
	if m != i: c+=1
	else: i+=1
print(c if c<n else"-1")
### BUGGY CODE ###

from copy import deepcopy
n,ma,mb=map(int,input().split())
el=[list(map(int,input().split())) for i in range(n)]
sa=sum(i[0] for i in el)
sb=sum(i[1] for i in el)
sa1=sa+1
sb1=sb+1

inf=10000000000
x=[[inf]*(sb1) for i in range(sa1)]
y=[[0]*(sb1) for i in range(sa1)]
x[0][0]=0
for i in range(n):
    now=el[i]
    x_sub=deepcopy(y)
    for k in range(sa1):
        for l in range(sb1):
            if x[k][l]!=inf:
                if k+now[0]<sa1:
                    if l+now[1]<sb1:
                        x_sub[k+now[0]][l+now[1]]=x[k][l]+now[2]
    for k in range(sa1):
        for l in range(sb1):
                if x_sub[k][l]!=0:
                    x[k][l]=min(x[k][l],x_sub[k][l])
mi=min(sa//ma,sb//mb)
ans=inf
for i in range(1,mi+1):
    ans=min(ans,x[ma*i][mb*i])
if ans==inf:
    print(-1)
else:
    print(ans)


### FIXED CODE ###

n,ma,mb=map(int,input().split())
el=[list(map(int,input().split())) for i in range(n)]
sa=sum(i[0] for i in el)
sb=sum(i[1] for i in el)
#mi=min(sa//ma,sb//mb)
inf=10000000000
x=[[inf for j in range(sb+1)] for i in range(sa+1)]
x[0][0]=0
for i in range(n):
    now=el[i]
    x_sub=[[0 for j in range(sb+1)] for i in range(sa+1)]
    for k in range(sa+1):
        for l in range(sb+1):
            if x[k][l]!=inf and k+now[0]<sa+1 and l+now[1]<sb+1:
                x_sub[k+now[0]][l+now[1]]=x[k][l]+now[2]
    for k in range(sa+1):
        for l in range(sb+1):
                if x_sub[k][l]!=0:
                    x[k][l]=min(x[k][l],x_sub[k][l])
mi=min(sa//ma,sb//mb)
ans=inf
for i in range(1,mi+1):
    ans=min(ans,x[ma*i][mb*i])
if ans==inf:
    print(-1)
else:
    print(ans)
### BUGGY CODE ###

# editorialを参考に作成
S = input()
lenS = len(S)
DP = [0] * 13
ans = [0]*13

if S[lenS-1] == "?":
    for j in range(10):
        ans[j % 13] += 1
else:
    ans[int(S[lenS-1]) % 13] += 1

for i in range(1, len(S)):
    DP = [0]*13
    for r in range(13):
        DP[r] += ans[r] % (10**9+7)
    ans = [0]*13
    i_mod = (10**i) % 13
    if S[lenS-i-1] == "?":
        for p in range(13):
            for h in range(10):
                ans[(p+h * i_mod) % 13] += DP[p]

    else:
        for q in range(13):
            ans[(q+i_mod * int(S[lenS-i-1])) % 13] = DP[q]


print(ans[5] % (10**9+7))
# print(DP)


### FIXED CODE ###

# editorialを参考に作成
S = input()
lenS = len(S)
DP = [0] * 13
ans = [0]*13
i_mod = [1] * lenS
if S[lenS-1] == "?":
    for j in range(10):
        ans[j % 13] += 1
else:
    ans[int(S[lenS-1]) % 13] += 1

for i in range(1, len(S)):
    DP = [0]*13
    for r in range(13):
        DP[r] += ans[r] % (10**9+7)
    ans = [0]*13
    i_mod[i] = (i_mod[i - 1] * 10) % 13
    i_now = 0
    i_now += i_mod[i]
    if S[lenS-i-1] == "?":
        for p in range(13):
            for h in range(10):
                ans[(p+h * i_now) % 13] += DP[p]

    else:
        for q in range(13):
            ans[(q+i_now * int(S[lenS-i-1])) % 13] = DP[q]


print(ans[5] % (10**9+7))
# print(DP)
### BUGGY CODE ###

n = int(input())
a = [int(i) for i in input().split()]
ans = 1
for i in range(n):
  ans *= a[i]
  
if ans > 10**18:
  print(-1)
else:
  print(ans)

### FIXED CODE ###

import sys
n = int(input())
a = [int(i) for i in input().split()]
ans = 1
if 0 in a:
  print(0)
else:
  for i in range(n):
    ans *= a[i]
    if ans > 10**18:
      print(-1)
      exit()
  print(ans)
### BUGGY CODE ###

sum=0
K=int(input())+1
r=1
for a in range(1,K):
  for b in range(1,K):
    for c in range(1,K):
      p=a
      q=b
      if p%q==0:
        r=q
      while p%q!=0:
        r=p%q
        p=q
        q=r
      
      p=r
      q=c
      if p%q==0:
        r=q
      while p%q!=0:
        r=p%q
        p=q
        q=r
      sum+=r
print(sum)

### FIXED CODE ###

import math
sum=0
K=int(input())+1
for a in range(1,K):
  for b in range(1,K):
    ab=math.gcd(a,b)
    for c in range(1,K):
      sum+=math.gcd(ab,c)
print(sum)
### BUGGY CODE ###

#d
def main():
    s=input()
    n=len(s)
    mod=10**9+7
    
    dp=[[0]*13 for _ in range(n)]
    if s[-1]=="?":
        dp[0]=[1,1,1,1,1,1,1,1,1,1,0,0,0]
    else:
        dp[0][int(s[-1])]=1
    
    for i in range(1,n):
        imod=10**i %13
        ss0=s[n-i-1]
        if ss0!="?":
            dp[i] = [ dp[i-1][(j-int(ss0)*imod)%13] %mod for j in range(13)]
        else:
            dp[i] = [sum( dp[i-1][(j-k*imod)%13] for k in range(10)) %mod for j in range(13) ]
    print(dp[-1][5])
    
if __name__ == '__main__':
    main()

### FIXED CODE ###

#d
def main():
    s=input()
    n=len(s)
    mod=10**9+7
    
    if s[-1]=="?":
        dp=[1,1,1,1,1,1,1,1,1,1,0,0,0]
    else:
        dp=[0]*13
        dp[int(s[-1])]=1
    
    for i in range(1,n):
        imod=10**(i %12)
        ss0=s[n-i-1]
        if ss0!="?":
            dpnew = [ dp[(j-int(ss0)*imod)%13] %mod for j in range(13)]
        else:
            dpnew = [sum( dp[(j-k*imod)%13] for k in range(10)) %mod for j in range(13) ]
        dp=dpnew[:]
    print(dp[5])
    
if __name__ == '__main__':
    main()
### BUGGY CODE ###

H,W,N = map(int,input().split())
B=[[0 for k in range(W-2)] for j in range(H-2)]
li=[-1,0,1]
for k in range(N):
    a,b=map(int,input().split())
    for n in range(3):
        for m in range(3):
            if 0<=a-2-li[m]<H-2 and 0<=b-2-li[n]<W-2:
                B[a-2-li[m]][b-2-li[n]]+=1
for k in range(10):
    c=0
    for j in range(H-2):
        c+=B[j].count(k)
    print(c)


### FIXED CODE ###

H,W,N = map(int,input().split())
Nli=[]
for k in range(N):
    a,b=map(int,input().split())
    for n in range(-1,2):
        for m in range(-1,2):
            if 0<=a-2-m<H-2 and 0<=b-2-n<W-2:
                Nli.append((b-n)*(H)+(a-m))
import collections
s = collections.Counter(Nli)
v = list(s.values())
print((H-2)*(W-2)-len(set(Nli)))
for k in range(1,10):
    print(v.count(k))
### BUGGY CODE ###

from functools import reduce
from fractions import gcd

def lcm_base(x, y):
    return (x * y) // gcd(x, y)

def lcm_list(l):
    lcm = l[0]
    for i in range(len(l)):
        lcm = lcm*l[i] // gcd(lcm, l[i])
    return lcm

mod = 10**9 + 7
n = int(input())
As = list(map(int, input().split()))

lcm = lcm_list(As)
b = [lcm//As[i] for i in range(n)]

print(sum(b) % mod)


### FIXED CODE ###

from functools import reduce
from fractions import gcd

def lcm_base(x, y):
    return (x * y) // gcd(x, y)

def lcm_list(numbers):
    return reduce(lcm_base, numbers)
mod = 10**9 + 7
n = int(input())
As = list(map(int, input().split()))

lcm = lcm_list(As)
b = [lcm//As[i] for i in range(n)]

print(sum(b) % mod)
### BUGGY CODE ###

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

ans = 1

for x in A:
        ans *= x
if ans > 10 ** 18:
        ans = -1
print(ans)

### FIXED CODE ###

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

ans = 1
ans_over = 0

for x in A:
        ans *= x
        if ans > 10 ** 18:
                ans = 1
                ans_over = 1

if ans_over == 1:
        if ans != 0:
                ans = -1


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

N, K = map(int, input().split())
costs = list(map(int, input().split())) + [0] * 10010


def chmin(i, j, dp, costs):
    if dp[i+j] > dp[i] + abs(costs[i] - costs[i+j]):
        dp[i+j] = dp[i] + abs(costs[i] - costs[i+j])
        return True
    return False


dp = [float('inf')] * 100010
dp[0] = 0
for i in range(N):
    for j in range(1, K+1):
        # print('i: %d  j: %d' % (i, j))
        chmin(i, j, dp, costs)
        # print(dp[0:N+20])

print(dp[N-1])

### FIXED CODE ###

N, K = map(int, input().split())
vals = list(map(int, input().split()))
costs = [0] * 100010
for i in range(len(vals)):
    costs[i] = vals[i]

dp = [float('inf')] * 100010
dp[0] = 0
for i in range(1, N):
    for j in range(1, K+1):
        if i-j >= 0:
            dp[i] = min(dp[i], dp[i-j] + abs(costs[i] - costs[i-j]))

# print(dp)
print(dp[N-1])
### BUGGY CODE ###

n,m=map(int,input().split())
s=input()
pos=n
p=n
tmp=n
ans=[]
while pos>0:
    q=p
    while pos-q<m and q>0:
        q-=1
        #print(q)
        if s[q]=='0':
            tmp=q
    #print()
    if tmp>=pos:
        print(-1)
        exit(0)
    ans.append(pos-tmp)
    pos=tmp
#print()
for i in range(1,1+len(ans)):
    print(ans[-i],end=' ')


### FIXED CODE ###

n,m=map(int,input().split())
s=input()
pos=n
p=n
tmp=n
ans=[]
while pos>0:
    q=p
    while pos-q<m and q>0:
        q-=1
        #print(q)
        if s[q]=='0':
            tmp=q
    p=q
    #print()
    if tmp>=pos:
        print(-1)
        exit(0)
    ans.append(pos-tmp)
    pos=tmp
#print()
for i in range(1,1+len(ans)):
    print(ans[-i],end=' ')
### BUGGY CODE ###

N,M = map(int,input().split())
 
LR = [set([]) for i in range(M)]
 
for i in range(M):
	L,R = map(int, input().split())
	for j in range(L,R + 1):
		LR[i].add(j)

for i in range(M):
	LR[i] = LR[i] & LR[i-1]
    
 
print(len(LR[M-1]))

### FIXED CODE ###

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

inf = []
sup = []

for i in range(0,M):
	L,R = map(int,input().split())
	inf.append(L)
	sup.append(R)
	
inf = max(inf)
sup = min(sup)

ran = sup - inf

if ran >= 0:
	print(ran + 1)
else:print(0)
### BUGGY CODE ###

import copy
import math

N = int(input())
xy = []
for _ in range(N):
    xy.append(tuple(map(int, input().split())))

def dfs(parent, p, q):
    tosee.remove(parent)
    for el in xy:
        if el in tosee:
            x, y = el
            if x + p == parent[0] and y + q == parent[1] or \
                    x - p == parent[0] and y - q == parent[1]:
                dfs(el,p,q)

m = N
for i in range(N - 1):
    for j in range(i + 1, N):
        p = xy[i][0] - xy[j][0]
        q = xy[i][1] - xy[j][1]
        cnt = 0
        tosee = copy.copy(xy)
        while tosee:
            el = tosee[0]
            dfs(el,p,q)
            cnt += 1
            # print(tosee)
        m = min(cnt, m)
        # print(p, q, group)
print(m)

### FIXED CODE ###

import copy
import math

N = int(input())
xy = []
for _ in range(N):
    xy.append(tuple(map(int, input().split())))

def dfs(parent, p, q):
    seen[parent] = True
    for child in range(N):
        # print(child)
        if seen[child] == False:
            x, y = xy[child]
            if x + p == xy[parent][0] and y + q == xy[parent][1] or \
                    x - p == xy[parent][0] and y - q == xy[parent][1]:
                dfs(child, p, q)


m = N
for i in range(N - 1):
    for j in range(i + 1, N):
        p = xy[i][0] - xy[j][0]
        q = xy[i][1] - xy[j][1]
        cnt = 0
        seen = [False] * N
        for start in range(N):
            if seen[start] == False:
                dfs(start, p, q)
                cnt += 1
                # print(tosee)
        m = min(cnt, m)
        # print(p, q, group)
print(m)
### BUGGY CODE ###

from collections import deque

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

E = [[] for _ in range(N)]
root = [True] * N
for _ in range(N-1+M):
    A,B = map(int,input().split())
    E[A-1].append(B-1)
    root[B-1] = False
root = root.index(True)

dist = [-1] * N
dist[root] = 0
parent = [-1] * N
q = deque([root])
while q:
    par = q.popleft()
    for e in E[par]:
        if dist[e] < dist[par] + 1:
            parent[e] = par
            dist[e] = dist[par] + 1
            q.append(e)

for ans in parent:
    print(ans + 1)

### FIXED CODE ###

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

# E[i]: 頂点iから伸びる頂点の集合
E = [[] for _ in range(N)]
# parent_cnt[i]: 頂点iの親
parent_cnt = [0] * N
for _ in range(N-1+M):
    A,B = map(int,input().split())
    E[A-1].append(B-1)
    parent_cnt[B-1] += 1

# 根を見つける
for i,num in enumerate(parent_cnt):
    if num == 0:
        root = i
        break

parent = [None] * N
parent[root] = 0

q = [root]
# DFS O(N+M)
while q:
    qq = []
    for V in q:
        for Vto in E[V]:
            parent_cnt[Vto] -= 1

            # 親が決定
            if parent_cnt[Vto] == 0:
                parent[Vto] = V + 1
                qq.append(Vto)
    
    q = qq

print(*parent, sep="\n")
### BUGGY CODE ###

# coding: utf-8
n = int(input())
renga_list = list(map(int, input().split()))

tmp_i = 0
i = 1
while(True):
#    print("i="+str(i))
#    renga_list = renga_list[tmp_i:]
#    print("renga_list="+str(renga_list))
    if i in renga_list[tmp_i:]:
        tmp_i = renga_list[tmp_i:].index(i) + tmp_i
        i += 1
    else:
        break

result = n - i + 1
if n == result:
    print(-1)
else:
    print(result)

### FIXED CODE ###

# coding: utf-8
n = int(input())
renga_list = list(map(int, input().split()))


i = 1

for renga in renga_list:
    if i == renga:
        i += 1
        
result = n - i + 1
if n == result:
    print(-1)
else:
    print(result)
### BUGGY CODE ###

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

dp = [0]*n 

for i in range(1,n):
    dp[i] = dp[i-1]+abs(h[i]-h[i-1])
    for j in range(2,k+1):
        if i-j>=0:
            dp[i] = min(dp[i-j]+abs(h[i]-h[i-j]), dp[i])
    
print(dp[-1])

### FIXED CODE ###

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

dp = [0]*n 

for i in range(1,n):
    dp[i] = dp[i-1]+abs(h[i]-h[i-1])
    for j in range(2,k+1):
        if i-j>=0:
            dp[i] = min(dp[i-j]+abs(h[i]-h[i-j]), dp[i])
    
print(dp[-1])
### BUGGY CODE ###

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

dp = [[10**9 for _ in range(K)] for _ in range(N)]
dp[0] = [0 for _ in range(K)]

for i in range(N):
    for l in range(K):
        if i-(l+1) >= 0:
            dp[i][l] = min(dp[i - (l + 1)]) + abs(h[i] - h[i - (l + 1)])
        else:
            dp[i][l] = min(dp[i])
print(min(dp[N-1]))


### FIXED CODE ###

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

dp = [[10**9 for _ in range(K+1)] for _ in range(N)]
dp[0] = [0 for _ in range(K+1)]

for i in range(N):
    for l in range(K):
        if i-(l+1) >= 0:
            dp[i][l] = dp[i - (l + 1)][K] + abs(h[i] - h[i - (l + 1)])
        else:
            dp[i][l] = min(dp[i])
        if l == K-1:
            dp[i][K] = min(dp[i])
print(min(dp[N-1]))
### BUGGY CODE ###

from collections import deque

N = int(input())
A = []
for _ in range(N):
    A.append(deque(x - 1 for x in map(int, input().split())))

num_game_left = N * (N - 1) // 2
num_days = 0
left_players = set(range(N))
while 0 < num_game_left:
    game_players = set()
    for i in left_players:
        if i in game_players:
            continue
        j = A[i][0]
        if A[j] and A[j][0] == i:
            game_players.add(i)
            game_players.add(j)
    num_game_left -= len(game_players) // 2

    if len(game_players) == 0:
        break

    num_days += 1
    for i in game_players:
        A[i].popleft()
        if not A[i]:
            left_players.remove(i)

if num_game_left == 0:
    print(num_days)
else:
    print(-1)

### FIXED CODE ###

N = int(input())
A = []
for _ in range(N):
    A.append([x - 1 for x in map(int, input().split())])

game = []
for p1 in range(N):
    p2 = A[p1][0]
    if A[p2][0] == p1 and p1 < p2:
        game.append((p1, p2))

cursors = [0] * N
days = 0
while game:
    days += 1
    new_game = []
    for p1, p2 in game:
        cursors[p1] += 1
        if cursors[p1] < N - 1:
            p3 = A[p1][cursors[p1]]
            if cursors[p3] < N - 1 and A[p3][cursors[p3]] == p1:
                new_game.append((p1, p3))
        cursors[p2] += 1
        if cursors[p2] < N - 1:
            p3 = A[p2][cursors[p2]]
            if cursors[p3] < N - 1 and A[p3][cursors[p3]] == p2:
                new_game.append((p2, p3))
    game = new_game

if all(c == N - 1 for c in cursors):
    print(days)
else:
    print(-1)
### BUGGY CODE ###

N = int(input())
As = list(map(int, input().split()))
def xor(L):
  r = L[0]
  for i in range(1, len(L)):
    r ^= L[i]
  return r
re = 0
r = 0
for l in range(0, N):
  while r < N:
    if sum(As[l:r+1]) == xor(As[l:r+1]):
      r += 1
    else:
      break
  #print(l, r)
  re += r-l
print(re)


### FIXED CODE ###

N = int(input())
As = list(map(int, input().split()))
def xor(L):
  r = L[0]
  for i in range(1, len(L)):
    r ^= L[i]
  return r
re = 0
r = 0
s = 0
x = 0
for l in range(0, N):
  #s += As[l]
  #x ^= As[l]
  while r < N:
    #print(l, r, s, x)
    if s+As[r] == x^As[r]:
      s += As[r]
      x ^= As[r]
    #if sum(As[l:r+1]) == xor(As[l:r+1]):
      r += 1
    else:
      break
  s -= As[l]
  x ^= As[l]
  #print(l, r)
  re += r-l
print(re)