#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, k, tmp1;
  cin >> n >> k;
  if (n == 1) {
    cout << 0;
    return 0;
  }
  tmp1 = k * (k - 1) / 2 + 1;
  if (tmp1 < n) {
    printf("-1");
    return 0;
  }
  long long l = 2, h = k - 1, mid, tmp2;
  while (l < h - 1) {
    mid = (l + h) / 2;
    tmp2 = mid * (mid - 1) / 2 + 1;
    if (tmp1 + 1 - tmp2 < n)
      h = mid - 1;
    else if (tmp1 + 1 - tmp2 >= n)
      l = mid;
  }
  long long mx = max(l, h), mn = min(l, h);
  if (tmp1 + 1 - (mx * (mx - 1) / 2 + 1) >= n) {
    cout << k - mx;
  } else if (tmp1 + 1 - (mn * (mn - 1) / 2 + 1) >= n)
    cout << k - mn;
  else
    cout << k - 1;
}
