{"problem":{"name":"Backfront","description":{"content":"You are given a sequence $(P_1,P_2,...,P_N)$ which is a permutation of the integers from $1$ through $N$. You would like to sort this sequence in ascending order by repeating the following operation: ","description_type":"Markdown"},"platform":"AtCoder","limit":{"time_limit":2000,"memory_limit":262144},"difficulty":"None","is_remote":true,"is_sync":true,"sync_url":null,"sign":"agc024_b"},"statements":[{"statement_type":"Markdown","content":"You are given a sequence $(P_1,P_2,...,P_N)$ which is a permutation of the integers from $1$ through $N$. You would like to sort this sequence in ascending order by repeating the following operation:\n\n*   Choose an element in the sequence and move it to the beginning or the end of the sequence.\n\nFind the minimum number of operations required. It can be proved that it is actually possible to sort the sequence using this operation.\n\n## Constraints\n\n*   $1 \\leq N \\leq 2\\times 10^5$\n*   $(P_1,P_2,...,P_N)$ is a permutation of $(1,2,...,N)$.\n*   All values in input are integers.\n\n## Input\n\nInput is given from Standard Input in the following format:\n\n$N$\n$P_1$\n$:$\n$P_N$\n\n[samples]","is_translate":false,"language":"English"}],"meta":{"iden":"agc024_b","tags":[],"sample_group":[["4\n1\n3\n2\n4","2\n\nFor example, the sequence can be sorted in ascending order as follows:\n\n*   Move $2$ to the beginning. The sequence is now $(2,1,3,4)$.\n*   Move $1$ to the beginning. The sequence is now $(1,2,3,4)$."],["6\n3\n2\n5\n1\n4\n6","4"],["8\n6\n3\n1\n2\n7\n4\n8\n5","5"]],"created_at":"2026-03-03 11:01:14"}}