# ABC148D - Brick Break

def main():

    N, *A = list(map(int, open(0).read().split()))

    remaining = 0

    cur = 0  # current index

    for target in range(1, N + 1):

        be_kept = False

        for i in range(cur, N):

            if A[i] == target:

                remaining += 1

                cur = i + 1

                be_kept = True

                break

        if not be_kept:

            break

    print((N - remaining if remaining else -1))





if __name__ == "__main__":

    main()

# ABC148D - Brick Break

def main():

    N, *A = list(map(int, open(0).read().split()))

    remaining = 0

    target = 1

    for i in A:

        if i == target:

            remaining += 1

            target += 1

    print((N - remaining if remaining else -1))





if __name__ == "__main__":

    main()

# ABC148D - Brick Break
def main():
    N, *A = list(map(int, open(0).read().split()))
    remaining = 0
    cur = 0  # current index
    for target in range(1, N + 1):
        be_kept = False
        for i in range(cur, N):
            if A[i] == target:
                remaining += 1
                cur = i + 1
                be_kept = True
                break
        if not be_kept:
            break
    print((N - remaining if remaining else -1))


if __name__ == "__main__":
    main()

# ABC148D - Brick Break
def main():
    N, *A = list(map(int, open(0).read().split()))
    remaining = 0
    target = 1
    for i in A:
        if i == target:
            remaining += 1
            target += 1
    print((N - remaining if remaining else -1))


if __name__ == "__main__":
    main()

-    cur = 0  # current index -    for target in range(1, N + 1): -        be_kept = False -        for i in range(cur, N): -            if A[i] == target: -                remaining += 1 -                cur = i + 1 -                be_kept = True -                break -        if not be_kept: -            break +    target = 1 +    for i in A: +        if i == target: +            remaining += 1 +            target += 1