using System; using static System.Console; using System.Linq; using System.Collections.Generic; class Program { static int NN => int.Parse(ReadLine()); static int[] NList => ReadLine().Split().Select(int.Parse).ToArray(); static int[][] NArr(long n) => Enumerable.Repeat(0, (int)n).Select(_ => NList).ToArray(); static string[] SList(long n) => Enumerable.Repeat(0, (int)n).Select(_ => ReadLine()).ToArray(); public static void Main() { Solve(); } static void Solve() { var n = NN; var a = NList; var pos = new int[n + 1]; for (var i = 0; i < n; ++i) pos[a[i]] = i; var ans = 0; for (var i = 1; i <= n; ++i) { if (a[pos[i]] > 0) { ++ans; a[pos[i]] = 0; if (pos[i] > 0) a[pos[i] - 1] = 0; } } WriteLine(ans); } }