#include <bits/stdc++.h>
using namespace std;
template <typename T>
void afill(T *arr, int size, T val) {
  fill(arr, arr + size, val);
}
long long mod;
double eps = 1e-9;
int n, t, m, q, k;
bool f(long long int mid, long long int split, long long int target, int &ans) {
  long long int sum =
      (split + 1L) * split / 2L - mid * (mid - 1L) / 2L - (split - mid);
  if (sum > target) return false;
  if (sum == target)
    ans = min(ans, (int)(split - mid + 1L));
  else {
    long long int need = target - (sum - 1L);
    if (need >= 2L && need < mid) ans = min(ans, (int)(split - mid + 2L));
  }
  return true;
}
int main() {
  ios_base::sync_with_stdio(0);
  long long int target, split;
  cin >> target >> split;
  if (target == 1)
    cout << 0 << '\n';
  else if (split >= target)
    cout << 1 << '\n';
  else {
    long long int lo = 2, hi = split;
    int ans = INT_MAX;
    while (lo < hi) {
      long long int mid = (lo + hi) >> 1;
      if (f(mid, split, target, ans))
        hi = mid;
      else
        lo = mid + 1L;
    }
    f(lo, split, target, ans);
    if (ans == INT_MAX)
      cout << -1 << '\n';
    else
      cout << ans << '\n';
  }
}
