Language: C++

fn lower_bound<T: std::cmp::Ord>(arr: &Vec<T>, b: T) -> usize {
    let (mut lt, mut ge) = (0, arr.len());
    // lt=-1にすると型強制しなきゃなのでここで確かめる
    if arr[lt] >= b {
        return 0;
    }
    while lt + 1 < ge {
        let m = (lt + ge) / 2;
        if arr[m] < b {
            lt = m;
        } else if arr[m] > b {
            ge = m;
        } else {
            return m;
        }
    }
    ge
}

fn main() {
    let n = read();
    let mut p: Vec<usize> = vec![];
    for _ in 0..n {
        p.push(read());
    }
    let mut q = vec![0; n];
    for i in 0..n {
        q[p[i] - 1] = i;
    }
    let mut prev = std::usize::MAX;
    let mut cont = 1;
    let mut anss = 0;
    for i in 0..n {
        if prev < q[i] {
            cont += 1;
        } else {
            cont = 1;
        }
        prev = q[i];
        anss = max(anss, cont);
    }
    println!("{}", n - anss);

    // let mut dp = vec![std::usize::MAX; n];
    // let mut ans = 0;
    // for i in 0..n {
    //     let b = lower_bound(&dp, v[i]);
    //     dp[b] = v[i];
    //     ans = max(ans, b + 1);
    // }
    // println!("{}", n - ans);
}

// =========
#[allow(unused_imports)]
use std::cmp::{max, min};
#[allow(unused_imports)]
use std::collections::{HashMap, HashSet};
#[allow(unused_imports)]
use std::process::exit;

#[allow(dead_code)]
const MOD: usize = 1000000007;

fn read<T: std::str::FromStr>() -> T {
    use std::io::Read;
    let stdin = std::io::stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

// =========


Compiler output:
a.cc:23:14: error: too many decimal points in number
   23 |     for _ in 0..n {
      |              ^~~~
a.cc:27:14: error: too many decimal points in number
   27 |     for i in 0..n {
      |              ^~~~
a.cc:33:14: error: too many decimal points in number
   33 |     for i in 0..n {
      |              ^~~~
a.cc:55:2: error: invalid preprocessing directive #[
   55 | #[allow(unused_imports)]
      |  ^
a.cc:57:2: error: invalid preprocessing directive #[
   57 | #[allow(unused_imports)]
      |  ^
a.cc:59:2: error: invalid preprocessing directive #[
   59 | #[allow(unused_imports)]
      |  ^
a.cc:62:2: error: invalid preprocessing directive #[
   62 | #[allow(dead_code)]
      |  ^
a.cc:1:1: error: 'fn' does not name a type
    1 | fn lower_bound<T: std::cmp::Ord>(arr: &Vec<T>, b: T) -> usize {
      | ^~
a.cc:20:1: error: 'fn' does not name a type
   20 | fn main() {
      | ^~
a.cc:56:1: error: 'use' does not name a type
   56 | use std::cmp::{max, min};
      | ^~~
a.cc:58:1: error: 'use' does not name a type
   58 | use std::collections::{HashMap, HashSet};
      | ^~~
a.cc:60:1: error: 'use' does not name a type
   60 | use std::process::exit;
      | ^~~
a.cc:63:10: error: found ':' in nested-name-specifier, expected '::'
   63 | const MOD: usize = 1000000007;
      |          ^
      |          ::
a.cc:63:7: error: 'MOD' does not name a type
   63 | const MOD: usize = 1000000007;
      |       ^~~
a.cc:65:1: error: 'fn' does not name a type
   65 | fn read<T: std::str::FromStr>() -> T {
      | ^~