#include <bits/stdc++.h>
using namespace std;
long long mod = 1e9 + 7;
void test_case() {
  long long n, k;
  cin >> n >> k;
  if (n == 1) {
    cout << "0";
    return;
  }
  if (n - 1 > k * (k - 1) / 2) {
    cout << "-1";
    return;
  }
  long long l = 1, r = k - 1, mid;
  long long ans;
  while (l <= r) {
    mid = l + (r - l) / 2;
    if (k * (k - 1) / 2 - mid * (mid - 1) / 2 <= n - 1) {
      ans = mid;
      r = mid - 1;
    } else {
      l = mid + 1;
    }
  }
  long long res = (k - mid);
  if (k * (k - 1) / 2 - mid * (mid - 1) / 2 < n - 1) res++;
  cout << res;
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  test_case();
}
