#include <bits/stdc++.h>
using namespace std;
int temp;
char ch;
int input() {
  temp = 0;
  ch = getchar();
  while (ch < '0' || ch > '9') ch = getchar();
  while (ch >= '0' && ch <= '9') {
    temp = (temp << 1) + (temp << 3) + ch - '0';
    ch = getchar();
  }
  return temp;
}
int main() {
  long long n, k, x, sum, count = 0;
  cin >> n >> k;
  if (n > (k * (k - 1)) / 2 + 1) {
    cout << "-1\n";
    return 0;
  }
  if (n == 1) {
    cout << "0\n";
    return 0;
  }
  if (n <= k) {
    cout << "1\n";
    return 0;
  }
  k = k - 1;
  while (n > 1) {
    if (n <= k || k == 1) {
      count++;
      break;
    }
    x = n / k;
    count += x;
    sum = (k - (x - 1)) * x + (x * (x - 1)) / 2;
    n -= sum;
    k = k - x;
  }
  cout << count << endl;
  return 0;
}
