#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int i, j, n, k;
  cin >> n >> k;
  long long int mx = k * (k + 1);
  mx /= 2;
  mx--;
  mx = mx - (k - 2);
  if (mx < n) {
    cout << "-1" << endl;
    return 0;
  }
  if (n == 1) {
    cout << "0" << endl;
    return 0;
  }
  long long int val = k * k - k - 2 * n - 2;
  long long int k2 = (k * (k + 1)) / 2;
  long long int mn = 2;
  mx = k;
  while (mx - mn > 1) {
    long long int mid = (mn + mx) / 2;
    long long int md = mid - 1;
    long long int mid2 = (md * (md + 1)) / 2;
    if (k2 - mid2 - k + md + 1 >= n) {
      mn = mid;
    } else {
      mx = mid - 1;
    }
  }
  long long int mid = mx;
  long long int md = mid - 1;
  long long int mid2 = (md * (md + 1)) / 2;
  if (k2 - mid2 - k + mid >= n) {
    mn = mid;
  }
  cout << k - mn + 1;
  return 0;
}
