#include <cstdio>

int v[200009];

int main() {
    int n;
    scanf("%d", &n);

    int ans = 0;
    for (int i = 1; i <= n; i++) {
        int x;
        scanf("%d", &x);

        v[x] = v[x - 1] + 1;
        if (v[x] > ans)
            ans = v[x];
    }
    printf("%d\n", n - ans);

    return 0;
}
