#include <bits/stdc++.h>
long long int gcd(long long int a, long long int b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
long long int exp(long long int x, long long int y, long long int mod) {
  long long int res = 1;
  x = x % mod;
  while (y > 0) {
    if (y & 1) res = (res * x) % mod;
    y = y >> 1;
    x = (x * x) % mod;
  }
  return res;
}
long long int modinverse(long long int x, long long int mod) {
  return exp(x, mod - 2, mod);
}
using namespace std;
const long long int inf = 0x3f3f3f3f3f3f3f3fll;
map<long long int, long long int> par;
pair<long long int, long long int> p[100001];
vector<long long int> g[100001];
void dfs(long long int v) {
  for (long long int i = 0; i < g[v].size(); i++) {
    long long int to = g[v][i];
    if (!par[to]) {
      par[to] = v;
      dfs(to);
    }
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  long long int n, k, mx, val, l, r, mid;
  cin >> n >> k;
  mx = (k - 2) * (k - 1) / 2;
  mx = mx + k;
  if (n == 1)
    cout << 0;
  else if (n > mx)
    cout << -1;
  else {
    l = 0;
    r = k - 2;
    while (r >= l) {
      mid = (l + r) / 2;
      val = ((k - 1) * k) / 2;
      val = val - ((k - mid - 1) * (k - mid)) / 2;
      val = val + k - mid;
      if (val >= n)
        r = mid - 1;
      else
        l = mid + 1;
    }
    cout << l + 1;
  }
  return 0;
}
