import java.io.FileNotFoundException; import java.io.PrintWriter; import java.util.Arrays; import java.util.Comparator; import java.util.Scanner; public class Main { public static void main(String[] args) throws FileNotFoundException { new Main().run(); } void run() { Scanner sc = new Scanner(System.in); PrintWriter pw = new PrintWriter(System.out); int N = sc.nextInt(); int p = 0; int[] A = new int[N]; for (int i = 0; i < N; ++i) { int a = sc.nextInt() - i; if (a <= 0) continue; A[p++] = a; } A = Arrays.copyOf(A, p); A = shrink(A); int[] dp = new int[N + 1]; Arrays.fill(dp, Integer.MAX_VALUE); for (int i = 0; i < A.length; ++i) { // int idx = Arrays.binarySearch(dp, A[i]); // if (idx >= 0) { // dp[idx + 1] = A[i]; // } else { // idx = -(idx + 1); // dp[idx] = A[i]; // } dp[gt(dp, A[i])] = A[i]; } int ans = 0; for (int i = 0; i < dp.length; ++i) { if (dp[i] >= Integer.MAX_VALUE) continue; ans = Math.max(ans, i + 1); } System.out.println(N - ans); } int[] shrink(int[] a) { int n = a.length; int[] ret = new int[n]; int[][] x = new int[n][2]; for (int i = 0; i < n; ++i) { x[i][0] = i; x[i][1] = a[i]; } Arrays.sort(x, new Comparator() { @Override public int compare(int[] o1, int[] o2) { return Long.compare(o1[1], o2[1]); } }); int p = 0; for (int i = 0; i < n; ++i) { ret[(int) x[i][0]] = p; if (i + 1 < n && x[i][1] != x[i + 1][1]) ++p; } return ret; } int gt(int[] A, int key) { int ok = A.length; int ng = -1; while (ok - ng > 1) { int m = (ok + ng) / 2; if (A[m] <= key) { ng = m; } else { ok = m; } } return ng + 1; } static void tr(Object... objects) { System.out.println(Arrays.deepToString(objects)); } }