Problem:
Score : 400 points

Problem Statement

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 1

3
2 1 2

Sample Output 1

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.

Sample Input 2

3
2 2 2

Sample Output 2

-1

In this case, there is no way to break some of the bricks to satisfy Snuke's desire.

Sample Input 3

10
3 1 4 1 5 9 2 6 5 3

Sample Output 3

7

Sample Input 4

1
1

Sample Output 4

0

There may be no need to break the bricks at all.

Solution in C# (Mono 4.6.2.0) (judge verdict: Wrong Answer)

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace _20191224_ATC
{
    class Program
    {
        static void Main(string[] args)
        {
            var n = Myself.NextInt()[0];
            var a = Myself.NextInt();

            int checkNum = 1;
            int ansNum = 0;
            int index = 0;
            for (int i = 0; i < a.Count; i++)
            {
                if(checkNum == a[i])
                {
                    if(checkNum == 1)
                    {
                        ansNum += i - index;
                    }
                    else
                    {
                        ansNum += i - index - 1;
                    }
                    index = i;
                    checkNum++;
                }
            }

            if (checkNum == 1)
            {
                Myself.Print(-1);
            }
            else
            {
                Myself.Print(ansNum);
            }
        }

        private static void ABC148_C()
        {
            var n = Myself.NextLong();
            var a = n[0];
            var b = n[1];

            //最小公倍数を求める問題
            var lcm = Utility.Lcm(a, b);
            Console.WriteLine(lcm);
        }

        private static void ABC148_B()
        {
            var m = int.Parse(Console.ReadLine());
            var str = Console.ReadLine().ToString().Split(' ');
            var s = str[0];
            var t = str[1];

            //Zip : 2つのリストから一個ずつ取り出して結合する
            //SelectMany : 結合したものを1文字ずつ1つのリストにまとめる
            var output = s.Zip(t, (x, y) => new[] { x, y }).SelectMany(xs => xs);
            //foreach (var item in output)
            //{
            //    Console.WriteLine(item);
            //}

            //char型のリストから文字列を生成
            Console.WriteLine(string.Join("", output));
        }

        private static void ABC148_A()
        {
            var a = int.Parse(Console.ReadLine());
            var b = int.Parse(Console.ReadLine());
            var c = Enumerable.Range(1, 3).Where(x => x != a && x != b).First();
            Console.WriteLine(c);
        }
    }

    public class Myself
    {
        public static List<int> NextInt()
        {
            return Console.ReadLine().Split(' ').Select(int.Parse).ToList();
        }

        public static List<long> NextLong()
        {
            return Console.ReadLine().Split(' ').Select(long.Parse).ToList();
        }

        public static List<double> NextDouble()
        {
            return Console.ReadLine().Split(' ').Select(double.Parse).ToList();
        }

        public static List<string> NextString()
        {
            return Console.ReadLine().Split(' ').ToList();
        }

        public static void Swap<T>(ref T a, ref T b)
        {
            T temp = a;
            a = b;
            b = temp;
        }

        /// <summary>
        /// コンソール出力関数
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="a"></param>
        public static void Print<T>(T a)
        {
            Console.WriteLine(a);
        }
    }

    public struct Point
    {
        public double X
        {
            get;
            set;
        }
        public double Y
        {
            get;
            set;
        }

        public Point(double x, double y)
        {
            X = x;
            Y = y;
        }

        public static Point CalcOffsetPoint(Point a, Point b)
        {
            b.X -= a.X;
            b.Y -= a.Y;

            return new Point(b.X, b.Y);
        }

        public static double CalcArea(Point a, Point b)
        {
            return Math.Abs((a.X * b.Y) - (a.Y * b.X)) / 2;
        }
    }

    class Utility
    {
        // 最小公倍数
        public static long Lcm(long a, long b)
        {
            return a * b / Gcd(a, b);
        }

        // ユークリッドの互除法 最大公約数
        private static long Gcd(long a, long b)
        {
            if (a < b)
            {
                return Gcd(b, a);
            }
            long d = 0;
            do
            {
                d = a % b;
                a = b;
                b = d;
            } while (d != 0);
            return a;
        }
    }
}