#include <bits/stdc++.h>
using namespace std;
bool valid(long long mid, long long b, long long n, long long k) {
  long long a;
  a = (k - mid) * (k - mid - 1) / 2;
  if (b - a + 1 >= n)
    return true;
  else
    return false;
}
long long bs(long long b, long long k, long long n) {
  long long st = 2, ed = k - 2, mid, res;
  while (st <= ed) {
    mid = (st + ed) / 2;
    if (valid(mid, b, n, k)) {
      res = mid;
      ed = mid - 1;
    } else
      st = mid + 1;
  }
  return res;
}
int main() {
  long long n, a, b, k, v;
  cin >> n >> k;
  b = k * (k - 1) / 2;
  if (n == 1)
    v = 0;
  else if (n <= k)
    v = 1;
  else if (n > b + 1)
    v = -1;
  else if (n == b + 1)
    v = k - 1;
  else {
    v = bs(b, k, n);
  }
  cout << v;
  return 0;
}
