#include <bits/stdc++.h>
#define ld long double
using namespace std;
#define IO ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)
typedef long long ll;

char file_name[100];

void set_output_path(string s)
{
    strcpy(file_name, s.c_str());
    // cout << file_name << '\n';
    freopen(file_name, "w", stdout);
}

string get_id(int num)
{
    if (num < 10)
        return "0" + to_string(num);
    return to_string(num);
}

void set_output_in(int num)
{
    set_output_path(get_id(num) + ".in");
}

void set_output_ok(int num)
{
    set_output_path(get_id(num) + ".ok");
}


const int N = 1001, K = 51, INF = 1e9;

int n, k, a[N], mem[N][N][K][2];

int dp(int i, int pre, int cnt_lm, bool pre_is_greaterThan_prepre)
{
    if (cnt_lm > k) return INF;
    if (i == n + 1) return cnt_lm == k ? 0 : INF;

    auto &ret = mem[i][pre][cnt_lm][pre_is_greaterThan_prepre];
    if (~ret) return ret;

    int c1 = 1 + dp(i + 1, pre, cnt_lm, pre_is_greaterThan_prepre); // leaave
    int c2 = INF;   // try to pick

    if (a[i] < a[pre] && pre_is_greaterThan_prepre)
    {
        c2 = dp(i + 1, i, cnt_lm + 1, 0);
    }
    else
    {
        c2 = dp(i + 1, i, cnt_lm, a[i] > a[pre]);
    }
    return ret = min(c1, c2);
}

void solve()
{
    a[0] = INF;
    memset(mem, -1, sizeof mem);
    auto ans = dp(1, 0, 0, 0);
    if (ans == INF)
    {
        ans = -1;
    }
    cout << ans;
}

void out(int tt, int lim)
{
    set_output_in(tt);
    cout << lim << ' ';
    n = lim;
    int k = rand() % 50 + 1;
    cout << k << '\n';
    int N = 1e9;
    for (int tc = 1; tc <= lim; tc++)
    {
        int z = rand() % N + 1;
        a[tc] = z;
        cout << z << '\n';
    }
    set_output_ok(tt);
    solve();
    // for (int tc = 1; tc <= lim; tc++)
    // {
    //   solve(tc);
    // }
}
int main()
{
    ///cout << fixed << setprecision(10);
    srand(0);
    // IO;
    ///int tc = 1, tt = 2;
    for (int i = 3; i <= 5; i++)
    {
        out(i, 10);
    }
    for (int i = 6; i <= 10; i++)
    {
        out(i, 100);
    }
    for (int i = 11; i <= 15; i++)
    {
        out(i, 1000);
    }
    for (int i = 15; i <= 20; i++)
    {
        out(i, 500);
    }
//    for (int i = 21; i <= 23; i++)
//    {
//        out(i, 100000);
//    }
    // out(4, 100);
    // out(4, 1000);
    // out(6, 100000);
    // out(8, 1000000);
    // solve();
}
