#include <bits/stdc++.h>
using namespace std;
long long bin(long long n, long long m) {
  long long lo = 0, hi = m, ans = -1;
  while (hi > lo) {
    long long mid = (hi + lo) / 2;
    if (((((m * (m - 1)) / 2) + 1) - (((mid * (mid + 1) / 2)))) >= n) {
      ans = (m - 1) - mid;
      lo = mid + 1;
    } else
      hi = mid;
  }
  return ans;
}
int main() {
  long long n, m;
  cin >> n >> m;
  long long ans = bin(n, m);
  cout << ans << endl;
  return 0;
}
