#include <bits/stdc++.h>
const int Inf = 2e9;
long long LINF = (long long)4e18;
using namespace std;
long long f(long long i, long long k) {
  long long r = k * (k + 1) / 2 - 1;
  long long l = max(0LL, (k - i) * (k - i + 1) / 2 - 1);
  return r - l - i + 1;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long n, k;
  cin >> n >> k;
  if (n == 1) {
    cout << 0;
    return 0;
  }
  long long ans = 0;
  while (n > 0 && k > 1) {
    long long l = 1, r = k - 1;
    while (l < r) {
      long long m = (l + r) / 2 + 1;
      long long cur = f(m, k);
      if (cur > n)
        r = m - 1;
      else
        l = m;
    }
    long long x = f(l, k) - (ans > 0);
    if (x <= n) {
      n -= x;
      ans += l;
      k -= l;
    } else
      k = min(k - 1, n + 1);
  }
  if (n > 0) ans = -1;
  cout << ans;
  return 0;
}
