#include <bits/stdc++.h>
int caseno = 1;
using namespace std;
typedef unsigned long long ULL;
typedef unsigned long long uint64;
typedef long long LL;
typedef long long int64;
template <class T>
inline void checkmax(T &a, T b) {
  if (b > a) a = b;
}
template <class T>
inline void checkmin(T &a, T b) {
  if (b < a) a = b;
}
template <class T>
inline T MAX(T a, T b) {
  return (a > b) ? a : b;
}
template <class T>
inline T MIN(T a, T b) {
  return (a < b) ? a : b;
}
template <class T>
inline T sqr(T x) {
  return x * x;
}
template <class T>
inline T fABS(T a) {
  return a < 0 ? a * (-1) : a;
}
template <class T>
inline void SWAP(T &a, T &b) {
  T t = a;
  a = b;
  b = t;
}
inline LL POW(LL base, LL power) {
  LL I, res = base;
  if (power == 0) return 1;
  for (I = 0; I < power - 1; I++) res *= base;
  return res;
}
bool isUpperCase(char c) { return c >= 'A' && c <= 'Z'; }
bool isLowerCase(char c) { return c >= 'a' && c <= 'z'; }
bool isVowel(char c) {
  return (c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u' ||
          c == 'A' || c == 'E' || c == 'I' || c == 'O' || c == 'U');
}
bool isLetter(char c) { return c >= 'A' && c <= 'Z' || c >= 'a' && c <= 'z'; }
bool isDigit(char c) { return c >= '0' && c <= '9'; }
char toLowerCase(char c) { return (isUpperCase(c)) ? (c + 32) : c; }
char toUpperCase(char c) { return (isLowerCase(c)) ? (c - 32) : c; }
int toInt(string s) {
  int r = 0;
  istringstream sin(s);
  sin >> r;
  return r;
}
double toDouble(string s) {
  double r = 0;
  istringstream sin(s);
  sin >> r;
  return r;
}
string toString(int n) {
  string s;
  stringstream convert;
  convert << n;
  s = convert.str();
  return s;
}
const double PI = 2 * acos(0.0);
const double EPS = 1e-11;
const int SIZE = 100000 + 1;
int ar[SIZE];
int main() {
  std::ios_base::sync_with_stdio(0);
  int tcases, I, J, K, N, n, m, cnt = 0, len, mx = 0;
  cin >> n;
  for (I = 1; I <= n; I++) {
    cin >> m;
    if (ar[m - 1] == 0)
      ar[m] = 1;
    else {
      ar[m] = 1 + ar[m - 1];
      ar[m - 1] = 0;
    }
  }
  mx = 0;
  for (I = 1; I <= n; I++) {
    mx = MAX(ar[I], mx);
  }
  cout << n - mx << '\n';
  return 0;
}
