#include <bits/stdc++.h>   using namespace std;   long long GCD(long long a, long long b) {     if (b == 0) return a;     return (a % b == 0 ? b : GCD(b, a % b));   }   long long POW(long long base, long long exp) {     long long val;     val = 1;     while (exp > 0) {       if (exp % 2 == 1) {         val = (val * base) % 1000000007;       }       base = (base * base) % 1000000007;       exp = exp / 2;     }     return val;   }   int a[100005];   int pos[100005];   int main() {     int n, i, c, mx;     scanf( %d , &n);     for (i = 1; i <= n; i++) {       scanf( %d , &a[i]);     }     for (i = 1; i <= n; i++) {       pos[a[i]] = i;     }     mx = 0;     for (i = 1; i <= n; i++) {       c = 1;       while (i < n && pos[i + 1] > pos[i]) {         i++;         c++;       }       mx = max(mx, c);     }     printf( %d n , n - mx);     return 0;   }   