#include <bits/stdc++.h>
using namespace std;
bool isGoogles = 0;
const long long maxn = 1e5 + 10;
const long long max_val = 2e5 + 10;
long long mod = 1000000007;
const long long bits = 10;
long long caseNumber = 1;
void jabru() {
  long long n;
  cin >> n;
  long long k;
  cin >> k;
  if (n == 1) {
    cout << 0 << "\n";
    return;
  }
  n--;
  k--;
  long long l = 1LL, r = k;
  while (r - l > 1) {
    long long mid = l + (r - l) / 2;
    long long gone = (mid * (mid - 1)) / 2;
    long long tot = (k * (k + 1)) / 2;
    long long rem = tot - gone;
    if (rem <= n) {
      r = mid;
    } else {
      l = mid;
    }
  }
  if ((k * (k + 1)) / 2 < n) {
    cout << -1 << "\n";
    return;
  }
  long long ans = k;
  long long mid = r;
  long long gone = (mid * (mid - 1)) / 2;
  long long tot = (k * (k + 1)) / 2;
  long long rem = tot - gone;
  if (rem >= n) {
    ans = min(ans, k - mid + 1);
  }
  mid = l;
  gone = (mid * (mid - 1)) / 2;
  tot = (k * (k + 1)) / 2;
  rem = tot - gone;
  if (rem >= n) {
    ans = min(ans, k - mid + 1);
  }
  cout << ans << "\n";
}
bool TestCase = 0;
void brain_wash() {}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  long long t;
  t = 1;
  if (TestCase) {
    cin >> t;
  }
  while (t--) {
    if (isGoogles) {
      cout << "Case #" << caseNumber << ": ";
    }
    caseNumber++;
    jabru();
    brain_wash();
  }
  return 0;
}
