Problem E. Um...

Problem

It is troublesome to design contest questions. It will be much better if someone can help...

You are given a permutation of 1,2,..., n. In each step, you can either move an integer to the front or move an integer to the end. What is the minimum number of steps to sort the permutation (in ascending order)?

Input

Each test case will start with an integer n, where 1 ≤ n ≤ 100,000. The next line contains a permutation of 1, 2, ..., n. The input ends when n = 0, which should not be processed.

Output

For each test case, output the minimum number of steps to sort the given permutation.

Sample Input

4
1 2 3 4
5
5 4 3 2 1
6
5 2 1 3 6 4
0

Sample output

0
4
3

Author

Heard from Hon Wing Kai