#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define int long long int
#define ld long double
#define all(x) x.begin(), x.end()
#define sortall(x) sort(all(x))
#define endl '\n'
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
template<class T>
void printC (T Collection)
{
    for (auto&i:Collection)
        cout << i << " \n";
    cout << '\n';
}

/*
 * Think twice, code once
 * Think of different approaches to tackle a problem: write them down.
 * Think of different views of the problem. don't look from only one side.
 * don't get stuck in one approach.
 * common mistakes: - over_flow
 *                  - out_of_bound index
 *                  - infinite loop
 *                  - corner cases
 *                  - duplication counting.
*/

void solve()
{
    int n, k; cin >> n >> k;
    int l = 2, r = k, ans = -1;
    if (n == 1)
    {
        cout << 0;
        return;
    }
    while (l <= r)
    {
        int mid = (l+r)>>1;
        if ([&](int)->bool
        {
            int have = k*(k+1)/2 - (mid-1)*mid/2 - (k-mid);
            return have >= n;
        }(mid))
        {
            ans = k-mid+1;
            l = mid + 1;
        }else
            r = mid - 1;
    }
    cout << ans;
}

int32_t main()
{
    // #ifndef ONLINE_JUDGE
    //     freopen("input.txt", "r", stdin);
    //     freopen("output.txt", "w", stdout);
    //     freopen("Errors.txt", "w", stderr);
    // #endif
    fast
    int t = 1;
    // cin >> t;
    while (t--)
    {
        solve();
        if (t) cout << '\n';
    }
    cout << '\n';
    return 0;
}