We have N bricks arranged in a row from left to right.
The i-th brick from the left (1 \leq i \leq N) has an integer a_i written on it.
Among them, you can break at most N-1 bricks of your choice.
Let us say there are K bricks remaining. Snuke will be satisfied if, for each integer i (1 \leq i \leq K), the i-th of those brick from the left has the integer i written on it.
Find the minimum number of bricks you need to break to satisfy Snuke's desire. If his desire is unsatisfiable, print -1 instead.

-----Constraints-----
 - All values in input are integers.
 - 1 \leq N \leq 200000
 - 1 \leq a_i \leq N

-----Input-----
Input is given from Standard Input in the following format:
N
a_1 a_2 ... a_N

-----Output-----
Print the minimum number of bricks that need to be broken to satisfy Snuke's desire, or print -1 if his desire is unsatisfiable.

-----Sample Input-----
3
2 1 2

-----Sample Output-----
1

If we break the leftmost brick, the remaining bricks have integers 1 and 2 written on them from left to right, in which case Snuke will be satisfied.

Difficulty: MEDIUM

Solutions:
n = int(input())
first = n
k = [int(x) for x in input().split()]
j = 1
for i in k:
	if i == j:
		j += 1
if j == 1:
	print('-1')
else:
	print(str(n - j + 1))


n = int(input())
a = list(map(int, input().split()))
s = 1
for j in range(n):
	if a[j] == s:
		s += 1
if s == 1:
	print(-1)
else:
	print(n - s + 1)


N = int(input())
a = [int(i) for i in input().split()]
k = 0
for i in range(N):
	if a[i] == k + 1:
		k += 1
if k != 0:
	print(N - k)
else:
	print(-1)


n = int(input())
A = list(map(int, input().split()))
c = 1
for a in A:
	if a == c:
		c += 1
if c == 1:
	print(-1)
else:
	print(n - c + 1)


n = int(input())
a = list(map(int, input().split()))
ans = 0
for i in a:
	if i == ans + 1:
		ans += 1
if ans == 0:
	print(-1)
else:
	print(n - ans)


n = int(input())
i = 1
for a in map(int, input().split()):
	if a == i:
		i += 1
if i == 1:
	print(-1)
else:
	print(n - i + 1)


N = int(input())
block = list(map(int, input().split()))
a = 1
for i in block:
	if i == a:
		a += 1
if a == 1:
	print(-1)
else:
	print(len(block) - a + 1)


n = int(input())
a = list(map(int, input().split()))
b = len(a)
result = 1
i = 0
j = 0
while True:
	if a[i] == result:
		result += 1
	i += 1
	if i >= b:
		break
if result == 1:
	print(-1)
else:
	print(b - result + 1)


N = int(input())
(*A,) = map(int, input().split())
b = 0
i = 1
for a in A:
	if a == i:
		i += 1
	else:
		b += 1
print(b if b != N else -1)


N = int(input())
a = [int(n) for n in input().split()]
i = 1
for j in range(N):
	if a[j] == i:
		i += 1
print(-1 if i == 1 else N - i + 1)


N = int(input())
A = list(map(int, input().split()))
n = 1
for i in range(N):
	if A[i] == n:
		n += 1
if n != 1:
	print(N + 1 - n)
else:
	print(-1)


n = int(input())
cnt = 0
for i in map(int, input().split()):
	if i == cnt + 1:
		cnt += 1
print(n - cnt if cnt else -1)


n = int(input())
a = list(map(int, input().split()))
now = 1
for x in a:
	if x == now:
		now += 1
print(-1 if now == 1 else n - now + 1)


import math
import statistics
a = int(input())
f = list(map(int, input().split()))
ans = 0
count = 0
for i in range(a):
	if ans + 1 == f[i]:
		ans = f[i]
		count += 1
if count > 0:
	print(len(f) - count)
else:
	print(-1)


n = int(input())
s = list(map(int, input().split()))
t = []
d = 0
for i in s:
	if i == d + 1:
		d = i
if d == 0:
	print(-1)
else:
	print(n - d)


n = int(input())
j = 1
for i in map(int, input().split()):
	if i == j:
		j += 1
print((-1, n - j + 1)[j != 1])


n = int(input())
a = [int(i) for i in input().split()]
d = 0
for i in a:
	if i - 1 == d:
		d = i
print(-1 if d == 0 else n - d)


n = int(input())
an = list(map(int, input().split()))
k = 0
for ai in an:
	if ai == k + 1:
		k += 1
if k == 0:
	print(-1)
else:
	print(n - k)


import math
n = int(input())
A = list(map(int, input().split()))
num = 1
brk = 0
for i in range(n):
	if A[i] == num:
		num += 1
	else:
		brk += 1
if num == 1 and brk != 0:
	print(-1)
else:
	print(brk)


n = int(input())
A = list(map(int, input().split()))
if not 1 in A:
	print(-1)
	return
num = 1
cnt = 0
for a in A:
	if a == num:
		num += 1
	else:
		cnt += 1
print(cnt)


n = int(input())
l = list(map(int, input().split()))
c = a = 0
for i in l:
	if i == c + 1:
		c += 1
	else:
		a += 1
if a == n:
	a = -1
print(a)


N = int(input())
A = [int(a) for a in input().split()]
c = 0
for a in A:
	if a == c + 1:
		c = a
print(N - c if c else -1)


N = int(input())
l = list(map(int, input().split()))
a = 1
for i in l:
	if a == i:
		a += 1
if a == 1:
	print(-1)
else:
	print(N - a + 1)


n = int(input())
a = list(map(int, input().split()))
x = 1
for i in range(n):
	if a[i] == x:
		x += 1
print(n - x + 1 if x > 1 else -1)


n = int(input())
arr = list(map(int, input().split()))
cnt = 0
for i in range(n):
	if arr[i] == cnt + 1:
		cnt += 1
if cnt == 0:
	print(-1)
else:
	print(n - cnt)


N = int(input())
k = 0
for x in map(int, input().split()):
	if x == k + 1:
		k += 1
print(N - k if k else -1)


N = int(input())
A = list(map(int, input().split()))
I = 0
for a in A:
	if a == I + 1:
		I += 1
if I == 0:
	print(-1)
else:
	print(N - I)


N = int(input())
A = list(map(int, input().split()))
j = 1
fg = 0
if N == 1:
	if A[0] == 1:
		print(0)
	else:
		print(-1)
else:
	for i in A:
		if i == j:
			j += 1
		else:
			fg += 1
	if j > 1:
		print(fg)
	else:
		print(-1)


import sys
from itertools import chain

def solve(N: int, A: 'List[int]'):
	cnt = 0
	for a in A:
		if a == cnt + 1:
			cnt += 1
	if cnt == 0:
		return -1
	return N - cnt

def main():
	tokens = chain(*(line.split() for line in sys.stdin))
	N = int(next(tokens))
	A = [int(next(tokens)) for _ in range(N)]
	answer = solve(N, A)
	print(answer)

def __starting_point():
	main()
__starting_point()


n = int(input())
a = [int(x) for x in input().split()]
x = 0
for i in range(n):
	if a[i] == x + 1:
		x += 1
if x != 0:
	print(n - x)
else:
	print(-1)


n = int(input())
a = list(map(int, input().split()))
b = 1
for i in range(n):
	if a[i] == b:
		b += 1
if b == 1:
	print(-1)
	exit()
print(n - b + 1)


n = int(input())
l = list(map(int, input().split()))
f = 1
c = 0
for i in range(n):
	if l[i] == f:
		c += 1
		f += 1
if c == 0:
	print(-1)
else:
	print(n - c)


n = int(input())
l = list(map(int, input().split()))
m = 0
for i in range(n):
	if m + 1 == l[i]:
		m += 1
if m == 0:
	print(-1)
else:
	print(n - m)


N = int(input())
a = list(map(int, input().split()))
if not 1 in a:
	print(-1)
	return
l = []
min_num = 0
for i in a:
	if i == min_num + 1:
		l.append(i)
		min_num += 1
print(N - len(l))


n = int(input())
A = list(map(int, input().split()))
ans = 0
find = 1
for i in range(n):
	if A[i] == find:
		find += 1
	else:
		ans += 1
if find == 1:
	ans = -1
print(ans)


n = int(input())
a = list(map(int, input().split()))
x = 0
for ai in a:
	if ai == x + 1:
		x += 1
ans = -1 if x == 0 else n - x
print(ans)


N = int(input())
A = [int(x) for x in input().split()]
cnt = 1
for i in A:
	if i == cnt:
		cnt += 1
if cnt == 1:
	print(-1)
else:
	print(N - cnt + 1)


n = int(input())
al = list(map(int, input().split()))
if n == 1 and al[0] == 1:
	print(0)
else:
	(i, j, num, ans) = (0, 0, 1, 0)
	while i < n:
		if al[i] != num:
			i += 1
		else:
			ans += i - j
			j = i + 1
			num += 1
			i += 1
	if num != 1 and j != n:
		ans += i - j
	if num == 1:
		print(-1)
	else:
		print(ans)


n = int(input())
a = [int(s) for s in input().split()]
num = 0
current = 1
for i in range(n):
	if a[i] == current:
		current += 1
	else:
		num += 1
print(num) if num != n else print(-1)


n = int(input())
a = list(map(int, input().split()))
i = 1
t = 0
for x in a:
	if x != i:
		t += 1
	else:
		i += 1
if len(a) == t:
	t = -1
print(t)


N = int(input())
a = map(int, input().split())
cnt = 1
for i in a:
	if cnt == i:
		cnt += 1
ans = N - cnt + 1
if cnt == 1:
	print(-1)
else:
	print(ans)


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


N = int(input())
a = list(map(int, input().split()))
j = 1
for i in range(N):
	if j == a[i]:
		j += 1
if j == 1:
	print(-1)
else:
	print(N - j + 1)


n = int(input())
lst = list(map(int, input().split()))
i = 1
for j in lst:
	if i == j:
		i += 1
print(-1 if i == 1 else n - i + 1)


N = int(input())
A = map(int, input().split())
x = 1
for a in A:
	if a == x:
		x += 1
ans = -1 if x == 1 else N - (x - 1)
print(ans)


N = int(input())
L = list(map(int, input().split()))
c = 1
for l in L:
	if l == c:
		c += 1
r = N - c + 1
if r == N:
	print(-1)
else:
	print(r)


N = int(input())
A = list(map(int, input().split()))
min = 1
check = True
count = 0
for i in range(N):
	if A[i] != min:
		A[i] = 0
		count += 1
	elif A[i] == min:
		min += 1
if A == [0] * N:
	print(-1)
else:
	print(count)


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


n = int(input())
brick = list(map(int, input().split()))
if 1 not in brick:
	print(-1)
else:
	a = 1
	for x in brick:
		if x == a:
			a += 1
	print(n - a + 1)


n = int(input())
A = list(map(int, input().split()))
f = 0
for a in A:
	if a == f + 1:
		f += 1
if f == 0:
	print(-1)
else:
	print(n - f)


n = int(input())
A = list(map(int, input().split()))
if not 1 in A:
	print(-1)
else:
	c = 1
	for i in range(n):
		if A[i] == c:
			c += 1
	print(n - c + 1)


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


n = int(input())
A = list(map(int, input().split()))
b = 0
a = 0
while a <= n - 1:
	if A[a] == b + 1:
		b = b + 1
	a = a + 1
if b != 0:
	print(n - b)
else:
	print(-1)


N = int(input())
a = list(map(int, input().split()))
i = 1
count = 0
for j in a:
	if i == j:
		i += 1
	else:
		count += 1
if N == count:
	print(-1)
else:
	print(count)


N = int(input())
a = list(map(int, input().split()))
if not 1 in a:
	print(-1)
	return
cnt = 0
for i in a:
	if i == cnt + 1:
		cnt += 1
print(N - cnt)


n = int(input())
l = list(map(int, input().split()))
val = 1
dif = 0
for a in l:
	if a == val:
		val += 1
		dif += 1
if val == 1:
	print(-1)
else:
	print(len(l) - dif)


N = int(input())
a = list(map(int, input().split()))
cnt = 0
for i in range(len(a)):
	if i + 1 - cnt != a[i]:
		cnt += 1
if cnt == N:
	print(-1)
else:
	print(cnt)


N = int(input())
A = list(map(int, input().split()))
(x, r) = (1, 0)
for a in A:
	if a == x:
		x += 1
	else:
		r += 1
print(-1 if r == N else r)


(n, *a) = map(int, open(0).read().split())
if 1 not in a:
	print(-1)
	exit()
cur = 0
for x in a:
	if cur + 1 == x:
		cur += 1
print(n - cur)


(n, *a) = map(int, open(0).read().split())
c = 1
for i in a:
	if i == c:
		c += 1
print(-1 * (c == 1) or n - c + 1)


N = int(input())
A = input().split()
C = 1
M = 0
for n in range(N):
	if int(A[n]) != C:
		M += 1
	else:
		C += 1
if M == N:
	M = -1
print(M)


N = int(input())
A = list(map(int, input().split()))
target = 1
ans = 0
for a in A:
	if a == target:
		target += 1
	else:
		ans += 1
print(ans if target != 1 else -1)


n = int(input())
a = list(map(int, input().split()))
(i, ans, j) = (1, 0, 0)
while j < n:
	if a[j] == i:
		i += 1
	else:
		ans += 1
	j += 1
if ans == n:
	print(-1)
else:
	print(ans)


N = int(input())
li = list(map(int, input().split()))
li_com = [i + 1 for i in range(N)]
an = 0
com = 0
for i in range(N):
	if li_com[com] == li[i]:
		com += 1
	else:
		an += 1
if com == 0:
	print(-1)
else:
	print(an)


import sys
N = int(input())
A = list(map(int, input().split()))
if A.count(1) == 0:
	print(-1)
	return
else:
	cnt = 0
	for a in range(len(A)):
		if A[a] == cnt + 1:
			cnt += 1
	print(len(A) - cnt)


n = int(input())
a = list(map(int, input().split()))
i = 1
cnt = 0
for x in a:
	if x == i:
		i += 1
	else:
		cnt += 1
if cnt == n:
	print(-1)
else:
	print(cnt)


N = int(input())
a = list(map(int, input().split()))
count = 0
cur = 1
for x in a:
	if x == cur:
		count += 1
		cur += 1
print(N - count if count != 0 else -1)


N = int(input())
con = 1
set = 0
s = list(map(int, input().split()))
for i in s:
	if con == i:
		set += 1
		con += 1
if set == 0:
	print(-1)
else:
	ans = len(s) - set
	print(ans)


(n, *a) = map(int, open(0).read().split())
(j, ans) = (1, 0)
for i in a:
	if i == j:
		j += 1
	else:
		ans += 1
print(ans if j != 1 else -1)


n = int(input())
a = list(map(int, input().split()))
count = 1
chk = False
for i in range(1, n + 1):
	if a[i - 1] == count:
		chk = True
		count += 1
print(n - count + 1 if chk else -1)


n = int(input())
a = [-1] + list(map(int, input().split()))
now = 0
for i in range(1, n + 1):
	if now + 1 == a[i]:
		now += 1
if now == 0:
	print(-1)
else:
	print(n - now)


N = int(input())
a_list = list(map(int, input().split()))
num = 1
ans = 0
for i in range(N):
	if a_list[i] != num:
		ans += 1
	else:
		num += 1
if num == 1:
	print(-1)
else:
	print(ans)


N = int(input())
A = input()
a = 1
for i in A.split():
	if int(i) == a:
		a += 1
if a == 1:
	print(-1)
else:
	print(N - a + 1)


N = int(input())
a = list(map(int, input().split()))
i = 0
b = 0
X = 1
while i < N:
	if a[i] == X:
		X += 1
	else:
		b += 1
	i += 1
if b == N:
	b = -1
print(b)


N = int(input())
A = list(map(int, input().split()))
l = 1
s = 0
for i in A:
	if i == l:
		l += 1
if l == 1:
	ans = -1
else:
	ans = N - l + 1
print(ans)


n = int(input())
num = list(map(int, input().split()))
cnt = 1
ans = 0
if 1 not in num:
	print(-1)
	return
for i in range(n):
	if num[i] == cnt:
		cnt += 1
	else:
		ans += 1
print(ans)


n = int(input())
l = list(map(int, input().split()))
if 1 not in l:
	print(-1)
else:
	i = 0
	j = 1
	cnt = 0
	while i < n:
		if l[i] == j:
			j += 1
		else:
			cnt += 1
		i += 1
	print(cnt)


n = int(input())
t = list(map(int, input().split(' ')))
x = 1
z = len(t) + 1
for i in range(n):
	if t[i] == x:
		z = x
		x += 1
print(len(t) - z)


n = int(input())
a = list(map(int, input().split()))
res = 0
num = 1
if 1 not in a:
	print(-1)
else:
	for ai in a:
		if ai == num:
			num += 1
		else:
			res += 1
	print(res)


N = int(input())
a = list(map(int, input().split()))
K = 0
for i in range(N):
	if a[i] == K + 1:
		K += 1
if K == 0:
	print(-1)
else:
	print(N - K)


n = int(input())
lst = list(map(int, input().split()))
x = 0
for i in lst:
	if i == x + 1:
		x = x + 1
if x == 0:
	print(-1)
else:
	print(n - x)


N = int(input())
a = map(int, input().split())
counter = 0
for ai in a:
	if counter + 1 == ai:
		counter += 1
print(N - counter if counter != 0 else '-1')


N = int(input())
A = [int(_) for _ in input().split()]
k = 0
for a in A:
	if a == k + 1:
		k += 1
if k == 0:
	print(-1)
else:
	print(N - k)


n = int(input())
a = list(map(int, input().split()))
key = 1
for i in range(n):
	if a[i] == key:
		key += 1
ans = n - key + 1
if key == 1:
	ans = -1
print(ans)


import sys
input = sys.stdin.readline

def main2():
	numbers = []
	N = int(input())
	numbers = list(map(int, input().split()))
	n = 1
	for x in numbers:
		if x == n:
			n += 1
	answer = N - n + 1
	if answer == N:
		answer = -1
	print(answer)

def main():
	numbers = []
	n = int(input())
	numbers = list(map(int, input().split()))
	buffer = [0]
	for i in range(1, n + 1):
		search_range = numbers[i - 1:]
		out_range = len(numbers[:i - 1])
		if i not in search_range and len(buffer) == 1:
			print(-1)
			return
		elif i not in search_range or i == n:
			break
		else:
			index = search_range.index(i)
			buffer.append(index - sum(buffer))
	print(sum(buffer))

def __starting_point():
	main2()
__starting_point()


def main():
	n = int(input())
	a = list(map(int, input().split()))
	s = 1
	ans = 0
	for i in range(n):
		if a[i] != s:
			ans += 1
		else:
			s += 1
	if ans == n:
		print(-1)
	else:
		print(ans)

def __starting_point():
	main()
__starting_point()


n = int(input())
alist = list(map(int, input().split()))
j = 0
for a in alist:
	if a == j + 1:
		j += 1
if j == 0:
	print(-1)
else:
	print(n - j)


N = int(input())
lsa = list(map(int, input().split()))
a = 1
for i in range(N):
	if lsa[i] == a:
		a += 1
if a == 1:
	ans = -1
else:
	ans = N - (a - 1)
print(ans)


n = int(input())
a = list(map(int, input().split()))
p = 1
for i in range(n):
	if a[i] == p:
		p += 1
x = p - 1
if x == 0:
	print(-1)
	exit()
print(n - x)


n = int(input())
a = list(map(int, input().split()))
cnt = 0
for v in a:
	if v == cnt + 1:
		cnt += 1
print(-1 if cnt == 0 else n - cnt)


from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache
import sys
sys.setrecursionlimit(10000)
INF = float('inf')
(YES, Yes, yes, NO, No, no) = ('YES', 'Yes', 'yes', 'NO', 'No', 'no')
(dy4, dx4) = ([0, 1, 0, -1], [1, 0, -1, 0])
(dy8, dx8) = ([0, -1, 0, 1, 1, -1, -1, 1], [1, 0, -1, 0, 1, 1, -1, -1])

def inside(y, x, H, W):
	return 0 <= y < H and 0 <= x < W

def ceil(a, b):
	return (a + b - 1) // b

def sum_of_arithmetic_progression(s, d, n):
	return n * (2 * s + (n - 1) * d) // 2

def gcd(a, b):
	if b == 0:
		return a
	return gcd(b, a % b)

def lcm(a, b):
	g = gcd(a, b)
	return a / g * b

def solve():
	N = int(input())
	A = list(map(int, input().split()))
	t = 1
	for i in range(N):
		if A[i] == t:
			t += 1
	if t == 1:
		print(-1)
	else:
		print(N - (t - 1))

def main():
	solve()

def __starting_point():
	main()
__starting_point()


n = int(input())
l = [int(i) for i in input().split()]
t = 1
for i in range(n):
	if l[i] == t:
		t += 1
if t > 1:
	print(n - t + 1)
else:
	print('-1')


N = int(input())
As = list(map(int, input().split()))
ans = 0
for a in As:
	if a == ans + 1:
		ans += 1
print(N - ans if ans > 0 else -1)


n = int(input())
ar = list(map(int, input().split()))
m = 0
for i in ar:
	if i - 1 == m:
		m = i
if m:
	print(n - m)
else:
	print(-1)


n = int(input())
ls = list(map(int, input().split()))
c = 1
for i in range(n):
	if c == ls[i]:
		c += 1
print(n - c + 1 if c > 1 else -1)


N = int(input())
a = list(map(int, input().split()))
now = 1
for x in a:
	if x == now:
		now += 1
if now == 1:
	now = N + 2
print(N - now + 1)


N = int(input())
curr = 0
for a in map(int, input().split()):
	if a == curr + 1:
		curr += 1
print(-1) if curr == 0 else print(N - curr)


N = int(input())
a = [int(i) for i in input().split()]
c = 1
for n in a:
	if n == c:
		c += 1
if c - 1:
	print(N - c + 1)
else:
	print(-1)


n = int(input())
a = list(map(int, input().split()))
cnt = 0
m = 1
for i in range(n):
	if a[i] == m:
		cnt += 1
		m += 1
if cnt == 0:
	print(-1)
else:
	print(n - cnt)


def main():
	N = int(input())
	A = list(map(int, input().split()))
	breakcount = 0
	cnt = 1
	for i in range(N):
		if A[i] != cnt:
			breakcount += 1
		else:
			cnt += 1
	if cnt == 1:
		print(-1)
		return
	print(breakcount)

def __starting_point():
	main()
__starting_point()


n = int(input())
a = [int(x) for x in input().split()]
c = 1
b = 0
for i in range(n):
	if a[i] == c:
		c += 1
	else:
		b += 1
if c == 1:
	res = -1
else:
	res = b
print(res)


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


N = int(input())
A = list(map(int, input().split()))
C = 1
D = 0
for i in range(N):
	if A[i] == C:
		C = C + 1
	else:
		D = D + 1
if D == N:
	D = -1
print(D)


N = int(input())
A = list(map(int, input().split()))
cur = 1
for a in A:
	if a == cur:
		cur += 1
if cur == 1:
	print(-1)
else:
	print(N - cur + 1)


n = int(input())
l = list(map(int, input().split()))
t = 1
ans = 0
for i in l:
	if i == t:
		t += 1
	else:
		ans += 1
if t == 1:
	ans = -1
print(ans)


N = int(input())
a = list(map(int, input().split()))
c = 0
for i in a:
	if i == c + 1:
		c += 1
print(N - c if c else -1)


n = int(input())
l = list(map(int, input().split()))
ans = 0
x = 1
for i in l:
	if i == x:
		x += 1
	else:
		ans += 1
if ans == len(l):
	print(-1)
else:
	print(ans)


n = int(input())
a = list(map(int, input().split()))
cur = 1
for e in a:
	if e == cur:
		cur += 1
cur -= 1
if cur:
	print(n - cur)
else:
	print(-1)


import math
ini = lambda : int(input())
inm = lambda : map(int, input().split())
inl = lambda : list(map(int, input().split()))
gcd = lambda x, y: gcd(y, x % y) if x % y else y

def factorization(n):
	arr = []
	temp = n
	for i in range(2, int(-(-n ** 0.5 // 1)) + 1):
		if temp % i == 0:
			cnt = 0
			while temp % i == 0:
				cnt += 1
				temp //= i
			arr.append([i, cnt])
	if temp != 1:
		arr.append([temp, 1])
	if arr == []:
		arr.append([n, 1])
	return arr

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

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

	def __str__(self):
		return '\n'.join(('{}: {}'.format(r, self.members(r)) for r in self.roots()))
mod = 10 ** 9 + 7
sigma = lambda x: x * (x + 1) // 2
n = ini()
a = inl()
p = 1
ans = 0
for i in range(n):
	if a[i] == p:
		p += 1
	else:
		ans += 1
ans = -1 if p == 1 else ans
print(ans)


n = int(input())
A = list(map(int, input().split()))
m = 1
ans = 0
for a in A:
	if a == m:
		m += 1
	else:
		ans += 1
if ans < n:
	print(ans)
else:
	print(-1)


N = int(input())
a = list(map(int, input().split()))
K = 0
for ai in a:
	if ai == K + 1:
		K += 1
print(N - K if K > 0 else -1)


N = int(input())
a = [int(x) for x in input().split()]
c = 1
for i in range(N):
	if a[i] == c:
		c += 1
print(N - c + 1 if c != 1 else -1)


N = int(input())
a = list(map(int, input().split()))
cur = 0
for num in a:
	if num == cur + 1:
		cur += 1
if cur == 0:
	print(-1)
else:
	print(N - cur)


n = int(input())
A = [int(x) for x in input().split()]
k = 1
for a in A:
	if a == k:
		k += 1
if k == 1:
	print(-1)
else:
	print(n - k + 1)


N = int(input())
l = list(map(int, input().split()))
flag_ary = [0] * (N + 1)
counter = 0
cur = 1
for i in l:
	if i == cur:
		counter += 1
		cur += 1
if counter == 0:
	print(-1)
else:
	print(N - counter)


def main():
	N = int(input())
	A = list(map(int, input().split()))
	ans = -1
	tmp = 1
	flg = False
	for a in A:
		if a == tmp:
			tmp += 1
			flg = True
	if flg:
		ans = N - tmp + 1
	print(ans)

def __starting_point():
	main()
__starting_point()


N = int(input())
ls = [int(s) for s in input().split()]
k = 1
for i in range(N):
	if ls[i] == k:
		k += 1
if k == 1:
	print(-1)
else:
	print(N - k + 1)


n = int(input())
a = list(map(int, input().split()))
temp = 1
res = []
for x in a:
	if x == temp:
		temp += 1
if temp == 1:
	print(-1)
else:
	print(n + 1 - temp)


def main():
	N = int(input())
	a = [int(x) for x in input().split()]
	cnt = 0
	for num in a:
		if num == cnt + 1:
			cnt += 1
	if cnt == 0:
		print(-1)
	elif cnt == N:
		print(0)
	else:
		print(N - cnt)

def __starting_point():
	main()
__starting_point()


(n, *a) = map(int, open(0).read().split())
now = 1
for i in a:
	if i == now:
		now += 1
print(-1 if 1 not in a else n - now + 1)


n = int(input())
a = list(map(int, input().split()))
cnt = 1
for ai in a:
	if ai == cnt:
		cnt += 1
print(n - (cnt - 1) if cnt > 1 else -1)


N = int(input())
A = list(map(int, input().split()))
num = 1
for i in A:
	if i == num:
		num += 1
if num == 1:
	print(-1)
else:
	print(N - (num - 1))


N = int(input())
a = [int(x) for x in input().split()]
cnt = 1
for x in a:
	if x == cnt:
		cnt += 1
print(-1 if cnt == 1 else N - cnt + 1)


n = int(input())
A = list(map(int, input().split()))
(tmp, cnt) = (1, 0)
for a in A:
	if a != tmp:
		cnt += 1
	else:
		tmp += 1
print(-1 if A.count(1) == 0 else cnt)


N = int(input())
A = list(map(int, input().split()))
cur = 0
for i in range(N):
	if A[i] == cur + 1:
		cur += 1
print(N - cur if cur != 0 else -1)


N = int(input())
a = input().split()
A = [int(b) for b in a]
n = 1
for a in A:
	if a == n:
		n += 1
if n == 1:
	print(-1)
else:
	print(N - n + 1)


N = int(input())
a = list(map(int, input().split()))
k = 1
ans = 0
for i in a:
	if i == k:
		k += 1
	else:
		ans += 1
if ans == N:
	ans = -1
print(ans)


N = int(input())
a = [int(i) for i in input().split()]
ans = 0
l = 1
for i in range(N):
	if l == a[i]:
		l += 1
	else:
		ans += 1
if ans == N:
	print(-1)
else:
	print(ans)


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


n = int(input())
l = list(map(int, input().split()))
cnt = 1
for i in l:
	if i == cnt:
		cnt += 1
if cnt != 1:
	print(n - cnt + 1)
else:
	print(-1)


n = int(input())
xs = [int(x) for x in input().split()]
c = 0
y = 1
for x in xs:
	if x == y:
		y += 1
	else:
		c += 1
print(-1 if c == n else c)


a = int(input())
l = list(map(int, input().split()))
num = 1
for i in l:
	if num == i:
		num += 1
if num - 1 == 0:
	print(-1)
else:
	print(a - num + 1)


n = int(input())
s = list(map(int, input().split()))
c = 0
for i in s:
	if i == c + 1:
		c += 1
if c == 0:
	print(-1)
else:
	print(n - c)


n = int(input())
A = list(map(int, input().split()))
mx = 0
tot = 0
for i in range(n):
	if A[i] != mx + 1:
		continue
	mx = A[i]
	tot += 1
if tot == 0:
	ans = -1
else:
	ans = n - tot
print(ans)


n = int(input())
ai = list(map(int, input().split()))
tmp = 1
ans = 0
for i in range(n):
	if ai[i] == tmp:
		tmp += 1
	else:
		ans += 1
if tmp == 1:
	ans = -1
print(ans)


(n, a) = open(0)
j = 0
for b in map(int, a.split()):
	if b == j + 1:
		j += 1
print([-1, int(n) - j][j > 0])


n = int(input())
A = list(map(int, input().split()))
if 1 not in A:
	print(-1)
	return
chk = 1
cnt = 0
for i in range(n):
	if A[i] == chk:
		cnt += 1
		chk += 1
print(len(A) - cnt)


a = int(input())
List = list(map(int, input().split()))
s = 0
for i in range(a):
	if List[i] == s + 1:
		s += 1
if s == 0:
	print(-1)
else:
	print(a - s)


n = int(input())
a = list(map(int, input().split()))
k = 0
for x in a:
	if x == k + 1:
		k += 1
if k == 0:
	print(-1)
else:
	print(n - k)


N = int(input())
A = list(map(int, input().split()))
next_number = 1
cnt = 0
for a in A:
	if a == next_number:
		next_number += 1
	else:
		cnt += 1
if cnt == len(A):
	print('-1')
else:
	print(cnt)


input()
a = input().split()
(b, c) = (0, 1)
for i in a:
	if int(i) == c:
		c += 1
	else:
		b += 1
print(b if c > 1 else -1)


n = int(input())
a = list(map(int, input().split()))
count = 0
tmp = 0
for i in range(n):
	if a[i] == tmp + 1:
		tmp = a[i]
	else:
		count += 1
print(count if count != n else -1)


n = int(input())
a = map(int, input().split())
j = 1
k = 0
for i in a:
	if i == j:
		k += 1
		j += 1
if k > 0:
	print(n - k)
else:
	print(-1)


(_, a) = open(0)
i = 1
c = 0
for a in a.split():
	f = int(a) != i
	c += f
	i += f ^ 1
print(-(i < 2) or c)


N = int(input())
a = list(map(int, input().split()))
n = 1
C = 0
for ai in a:
	if ai != n:
		C += 1
	else:
		n += 1
if n == 1:
	print('-1')
else:
	print(C)


import sys

def resolve(in_):
	N = int(next(in_))
	A = tuple(map(int, next(in_).split()))
	ans = 0
	x = 1
	for a in A:
		if x == a:
			x += 1
		else:
			ans += 1
	if N == ans:
		ans = -1
	return ans

def main():
	answer = resolve(sys.stdin)
	print(answer)

def __starting_point():
	main()
__starting_point()


(_, *a) = map(int, open(0).read().split())
(p, c) = (1, 0)
for i in a:
	c += i != p
	p += i == p
print(-1 if p == 1 else c)


a = int(input())
b = list(map(int, input().split()))
c = 1
ans = 0
for i in b:
	if i == c:
		c += 1
	else:
		ans += 1
if ans == a:
	ans = -1
print(ans)


n = int(input())
c = list(map(int, input().split()))
ans = 0
for i in range(n):
	if c[i] - 1 + ans != i:
		ans += 1
if ans == n:
	print(-1)
else:
	print(ans)


n = int(input())
l = list(map(int, input().split()))
now = 1
for i in range(n):
	if l[i] == now:
		now += 1
if now == 1:
	print(-1)
else:
	print(n - now + 1)


N = int(input())
A = list(map(int, input().split()))
ans = 1
for i in A:
	if i == ans:
		ans += 1
print('-1' if ans == 1 else len(A) - ans + 1)


n = int(input())
a_l = list(map(int, input().split()))
ans = 0
i = 0
j = 0
while i < n:
	if a_l[i] == j + 1:
		j += 1
		i += 1
		continue
	ans += 1
	i += 1
if ans > n - 1:
	print('-1')
else:
	print(ans)


n = int(input())
a = [int(i) for i in input().split()]
k = 0
flg = False
for ai in a:
	if ai == k + 1:
		k += 1
	else:
		flg = True
if k == 0 and flg:
	print(-1)
else:
	print(n - k)


n = int(input())
k = 0
for x in map(int, input().split()):
	if x == k + 1:
		k += 1
print(n - (k or n + 1))


N = int(input())
a = list(map(int, input().split()))
targetnum = 1
breaknum = 0
for i in range(N):
	if a[i] == targetnum:
		targetnum += 1
	else:
		breaknum += 1
if breaknum == N:
	print(-1)
else:
	print(breaknum)


n = int(input())
a = list((int(x) for x in input().split()))
count = 0
z = True
j = 0
if 1 not in a:
	print(-1)
else:
	for k in range(j, n):
		if a[k] == count + 1:
			j = k
			count = count + 1
	print(n - count)


N = int(input())
A = list(map(int, input().split()))
cnt = 0
idx = 1
for (i, a) in enumerate(A):
	if idx == a:
		idx += 1
	else:
		cnt += 1
if cnt == N:
	print(-1)
else:
	print(cnt)


n = int(input())
l = list(map(int, input().split()))
t = 1
for x in l:
	if x == t:
		t += 1
print(n + 1 - t if t > 1 else -1)


N = int(input())
A = list(map(int, input().split()))
i = 0
j = 0
while i < N:
	if A[i] == j + 1:
		j += 1
	i += 1
print(N - j if j != 0 else -1)


N = int(input())
A = list(map(int, input().split()))
i = 1
ans = 0
for x in A:
	if x == i:
		i += 1
	else:
		ans += 1
if ans == N:
	ans = -1
print(ans)


N = int(input())
A = list(map(int, input().split()))
s = 1
c = 0
for i in range(N):
	if A[i] == s:
		s = s + 1
		c = c + 1
if s == 1:
	print(-1)
else:
	print(N - c)


n = int(input())
a = list(map(int, input().split()))
ans = 1
cnt = 0
if ans not in a:
	print(-1)
	return
for i in a:
	if i == ans:
		ans += 1
		continue
	cnt += 1
print(cnt)


n = int(input())
lst = list(map(int, input().split()))
tmp = 0
for i in range(n):
	if tmp + 1 == lst[i]:
		tmp += 1
print(n - tmp if tmp > 0 else -1)


N = int(input())
List = list(map(int, input().split()))
j = 1
res = 0
for i in range(N):
	if List[i] == j:
		j += 1
	else:
		res += 1
if j == 1:
	res = -1
print(res)


n = int(input())
R = list(map(int, input().split()))
(c, i) = (0, 1)
for r in R:
	if r == i:
		i += 1
	else:
		c += 1
print(c if c < n else '-1')