#include <bits/stdc++.h>
using namespace std;
using ll = long long;
void solve() {
  ll n, k;
  cin >> n >> k;
  if (n == 1)
    cout << "0\n";
  else if (k >= n)
    cout << "1\n";
  else {
    if (n > (k * k - k + 2) / 2)
      cout << "-1\n";
    else {
      ll res = k - 1;
      ll st = 1, ed = k - 1;
      while (st <= ed) {
        ll mid = (st + ed) / 2;
        ll t = (k - mid);
        ll aux = (k * k + k) / 2 - (t * t + t) / 2;
        aux -= mid;
        aux++;
        if (aux >= n) {
          res = mid;
          ed = mid - 1;
        } else {
          st = mid + 1;
        }
      }
      cout << res;
    }
  }
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  solve();
  return 0;
}
