fn main() { let stdin = std::io::read_to_string(std::io::stdin()).unwrap(); let mut stdin = stdin.split_ascii_whitespace(); let n: usize = stdin.next().unwrap().parse().unwrap(); let a: Vec = (0..n) .map(|_| stdin.next().unwrap().parse().unwrap()) .collect(); println!("{}", output(solve(a))); } fn solve(a: Vec) -> usize { let n = a.len(); let mut lis = Vec::with_capacity(a.len()); a.into_iter().for_each(|a| { let idx = mylib::lower_bound(&lis, &a); if idx != lis.len() { lis[idx] = a; } else { lis.push(a); } }); n - lis.len() } fn output(ans: usize) -> usize { ans } mod mylib { pub fn lower_bound(v: &[T], border: &T) -> usize { if v.is_empty() || v[0] >= *border { return 0; } let mut l: usize = 0; let mut r: usize = v.len(); while l + 1 < r { let c = (l + r) / 2; if v[c] < *border { l = c; } else { r = c; } } r } }