#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const int msz = 10000;
const int mod = 1e9 + 7;
const double eps = 1e-8;
int k;
long long n;
int cal(long long x) {
  if (x * k - x * (x + 1) / 2 == n - 1) return 1;
  long long tmp = n - 1 - (x - 1) * k + (x - 1) * x / 2;
  if (tmp < 1) return -1;
  if (tmp >= k - x) return 0;
  return 1;
}
int main() {
  scanf("%lld%d", &n, &k);
  int ans = -1;
  int l, r;
  l = 0, r = k - 1;
  while (l <= r) {
    int mid = (l + r) >> 1;
    int s = cal(mid);
    if (s) {
      if (s == 1) ans = mid;
      r = mid - 1;
    } else
      l = mid + 1;
  }
  printf("%d\n", ans);
  return 0;
}
