#include using namespace std; int ans[100001], n, inp, max_ans; int main(){ cin >> n; for(int i=0; i> inp; ans[inp] = ans[inp-1] + 1; } for(int i=1; i<=n; ++i){ max_ans = max(max_ans, ans[i]); } cout << n - max_ans << endl; }