#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long n, k, b, e;
  cin >> n >> k;
  if (n == 1) {
    cout << '0' << endl;
    return 0;
  }
  long long p = ((k - 1) * k) / 2 - 1;
  if (n >= 2 && n <= (p + 2)) {
    b = 2;
    e = k - 2;
    if (n == p + 2)
      cout << k - 1 << endl;
    else if (n >= 2 && n <= k)
      cout << '1' << endl;
    else {
      while (b <= e) {
        long long mid = (e + b) / 2;
        long long g = k - mid + 1;
        long long begin = (k * (k + 1)) / 2 - (g * (g + 1)) / 2;
        long long f = mid - 2;
        begin = begin - f + 1;
        g--;
        long long end = (k * (k + 1)) / 2 - (g * (g + 1)) / 2;
        long long f2 = mid - 1;
        end = end - f2;
        if (n >= begin && n <= end) {
          cout << mid << endl;
          break;
        } else if (n > end)
          b = mid + 1;
        else
          e = mid - 1;
      }
    }
  } else
    cout << "-1" << endl;
  return 0;
}
