#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
const int N = 100005;
int dp[N];
int a[N], pos[N];
int main() {
  int n;
  while (~scanf("%d", &n)) {
    for (int i = 1; i <= n; i++) scanf("%d", &a[i]), pos[a[i]] = i;
    int len = 1;
    dp[1] = 1;
    for (int i = 1; i <= n - 1; i++) {
      if (a[i + 1] == 1)
        dp[i + 1] = 1;
      else {
        if (pos[a[i + 1] - 1] < i + 1)
          dp[i + 1] = dp[pos[a[i + 1] - 1]] + 1;
        else
          dp[i + 1] = 1;
      }
      len = max(len, dp[i + 1]);
    }
    printf("%d\n", n - len);
  }
  return 0;
}
