import std.algorithm;
import std.bigint;
import std.bitmanip;
import std.concurrency : generator = Generator, yield;
import std.container;
import std.conv;
import std.functional;
import std.format;
import std.math;
import std.meta;
import std.numeric;
import std.random;
import std.range;
import std.stdio;
import std.string;
import std.traits;
import std.typecons;


auto solve(long N, long[] a) {
    long wannaPreserve = 1;
    long preserved;

    foreach (ai; a) {
        if (ai == wannaPreserve) {
            preserved++;
            wannaPreserve++;
        }
    }

    if (preserved == 0)
        return -1;

    return N - preserved;
}


void main() {
    auto input = stdin.byLine.map!split.joiner;

    long N;
    N = input.front.to!long;
    input.popFront;

    long[] a = new long[](cast(size_t) (N));
    foreach (i; 0 .. cast(size_t) (N)) {
        a[i] = input.front.to!long;
        input.popFront;
    }

    static if (is(ReturnType!solve == void))
        solve(N, a);
    else {
        auto ans = solve(N, a);

        static if (isFloatingPoint!(ReturnType!solve))
            writeln(format("%.9f", ans));
        else static if (is(ReturnType!solve == bool))
            writeln(ans ? YES : NO);
        else
            writeln(ans);
    }
}
