human
An infinitely long railway has a train consisting of n cars, numbered from 1 to n (the numbers of all the cars are distinct) and positioned in arbitrary order. David Blaine wants to sort the railway cars in the order of increasing numbers. In one move he can make one of the cars disappear from its place and teleport it either to the beginning of the train, or to the end of the train, at his desire. What is the minimum number of actions David Blaine needs to perform in order to sort the train?

Input

The first line of the input contains integer n (1 ≤ n ≤ 100 000) — the number of cars in the train. 

The second line contains n integers pi (1 ≤ pi ≤ n, pi ≠ pj if i ≠ j) — the sequence of the numbers of the cars in the train.

Output

Print a single integer — the minimum number of actions needed to sort the railway cars.

Examples

Input

5
4 1 2 5 3

Output

2

Input

4
4 1 3 2

Output

2

Note

In the first sample you need first to teleport the 4-th car, and then the 5-th car to the end of the train.
Solve the task in PYTHON3.
assistant
#Here is Python program to print a single integer — the minimum number of actions needed to sort the railway cars.

#!/usr/bin/env python3
# 606C_sort.py - Codeforces.com/problemset/problem/606/C by Sergey 2015

import unittest
import sys

###############################################################################
# Sort Class (Main Program)
###############################################################################

class Sort:
    """ Sort representation """

    def __init__(self, test_inputs=None):
        """ Default constructor """

        it = iter(test_inputs.split("\n")) if test_inputs else None

        def uinput():
            return next(it) if it else sys.stdin.readline().rstrip()

        # Reading single elements
        [self.n] = map(int, uinput().split())

        # Reading a single line of multiple elements
        self.nums = list(map(int, uinput().split()))

        # Translate number to position
        tr = [0] * self.n
        for i in range(self.n):
            tr[self.nums[i]-1] = i

        # Longest increasing subarray
        max_len = 1
        for i in range(self.n):
            if i > 0 and tr[i] > tr[i-1]:
                cur_len += 1
                max_len = max(max_len, cur_len)
            else:
                cur_len = 1

        self.result = self.n - max_len

    def calculate(self):
        """ Main calcualtion function of the class """

        return str(self.result)

###############################################################################
# Unit Tests
###############################################################################

class unitTests(unittest.TestCase):

    def test_single_test(self):
        """ Sort class testing """

        # Constructor test
        test = "5\n4 1 2 5 3"
        d = Sort(test)
        self.assertEqual(d.n, 5)
        self.assertEqual(d.nums, [4, 1, 2, 5, 3])

        # Sample test
        self.assertEqual(Sort(test).calculate(), "2")

        # Sample test
        test = "4\n4 1 3 2"
        self.assertEqual(Sort(test).calculate(), "2")

        # Sample test
        test = "8\n6 2 1 8 5 7 3 4"
       ...