codeparrot/codecomplex huggingface dataset:
// Problem: 287_B. Pipeline
// Time complexity: logn
import java.math.*;
import java.util.*;

public class Main {
	public static void main(String[] args) throws Exception {
		Scanner scan = new Scanner(System.in);
		long n = scan.nextLong();
		long k = scan.nextLong();
		long total = k * (k - 1) / 2 + 1;
		if (total < n) {
			System.out.println(-1);
			return;
		}
		
		long left = total - n;
		long low = 1;
		long high = k - 1;
		while (low < high) {
			long mid = (low + high) / 2;
			long temp = mid * (mid + 1) / 2;
			if (temp < left) {
				low = mid + 1;
			} else {
				high = mid;
			}
		}
		long temp = low * (low + 1) / 2;
		if (temp == left) {
			System.out.println(k - 1 - low);
		} else {
			System.out.println(k - low);
		}
	}
}
// Problem: 287_B. Pipeline
// Time complexity: logn
import java.util.Arrays;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.Map;
import java.util.Queue;
import java.util.Scanner;
import java.util.ArrayList;
public class Main {

    static int d[][];
    static int N;
    static boolean used[];
    static class point
    {
        int x = 0;
        int y = 0;
    }
    static point dats[];
     
    public static void main(String[] args) 
    {
        Scanner scan = new Scanner(System.in);
        
        
        long n = scan.nextLong();
        long k = scan.nextLong();
        if(n==1)
        {
            System.out.print("0");
            return;
        }
        if(n<=k) 
        {
            System.out.print("1");
            return;
        }
        long d = 9-4*(2*n-k*k+k);
        if(d<0) 
        {
            System.out.print("-1");
            return;
        }
        double a = ((3+Math.sqrt(d)) / 2) ;
            if(a>=1)
                System.out.println(Math.max(2, k-(long)a+1));
            else
            System.out.println(-1);
        
        
    }
    

}
// Problem: 287_B. Pipeline
// Time complexity: logn


import java.math.BigInteger;
import java.util.Scanner;

public class B {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long n = sc.nextLong();
        long k = sc.nextLong();
        if (n == 1) {
            System.out.println(0);
        } else if (n <= k) {
            System.out.println(1);
        } else {
            n--;
            k--;
            BigInteger K = BigInteger.valueOf(k);
            BigInteger N = BigInteger.valueOf(n);
            BigInteger high = BigInteger.valueOf(k + 1);
            BigInteger low = BigInteger.valueOf(1);
            BigInteger mid;
            while (low.compareTo(high) < 0) {
                mid = low.add(high.subtract(low).shiftRight(1));
                BigInteger elemCnt = K.subtract(mid).add(BigInteger.ONE);
                BigInteger sum = elemCnt.multiply(
                        mid.shiftLeft(1).add(elemCnt.subtract(BigInteger.ONE)))
                        .shiftRight(1);
                if (sum.compareTo(N) > 0) {
                    low = mid.add(BigInteger.valueOf(1));
                } else {
                    high = mid;
                }
            }
            BigInteger elemCnt = K.subtract(low).add(BigInteger.ONE);
            BigInteger sum = elemCnt.multiply(
                    low.shiftLeft(1).add(elemCnt.subtract(BigInteger.ONE)))
                    .shiftRight(1);
            BigInteger rem = N.subtract(sum);
            if (rem.equals(BigInteger.ZERO)) {
                System.out.println(elemCnt);
            } else if (rem.compareTo(low) < 0) {
                System.out.println(elemCnt.add(BigInteger.ONE));
            } else {
                System.out.println(-1);
            }
        }
    }
}
// Problem: 287_B. Pipeline
// Time complexity: logn
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.PrintWriter;
import java.util.Scanner;

public class B176 {
    public static void main(String[] args) {
        Scanner in = new Scanner(new BufferedInputStream(System.in));
        PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out));
        long n = in.nextLong() - 1;
        long k = in.nextLong() - 1;
        if (k * (k + 1) / 2 < n) out.println(-1);
        else if (n == 0) out.println(0);
        else if (n < k) out.println(1);
        else {
            long t = binSearch(n, k, 1, k);
            long ans = k - t + 1;
            if (k * (k + 1) / 2 - t * (t - 1) / 2 != n) ans++;
            out.println(ans);
        }
        out.close();
    }

    private static long binSearch(long n, long k, long from, long to) {
        if (from == to) return from;
        long mid = (from + to) / 2;
        if (k * (k + 1) / 2 - mid * (mid - 1) / 2 > n) return binSearch(n, k, mid + 1, to);
        else return binSearch(n, k, from, mid);
    }
}
// Problem: 287_B. Pipeline
// Time complexity: logn
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;

public class Main {
	
	public static void main(String[] args) {
		try {
			BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
			PrintWriter pw = new PrintWriter(System.out);
			
			String[] param = br.readLine().split(" ");
			long n = Long.parseLong(param[0])-1;
			long k = Long.parseLong(param[1])-1;
			long max = k*(k+1)/2;
			long answer;
			if (n > max) answer = -1;
			else {
				long margin = max - n;
				long m = Math.max(0,(long)Math.floor((1.0+Math.sqrt(1+8*margin))/2.0)-1);
				long min = m*(m+1)/2;
				while (min <= margin) { m++; min = m*(m+1)/2; }
				answer = k - m + 1;
			}
			pw.println(answer);
			
			pw.close();
			br.close();
		} catch (IOException e) {
			e.printStackTrace();
			return;
		}
	}
}
// Problem: 287_B. Pipeline
// Time complexity: logn
import java.io.OutputStream;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.InputMismatchException;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 * @author George Marcus
 */
public class Main {
	public static void main(String[] args) {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		TaskB solver = new TaskB();
		solver.solve(1, in, out);
		out.close();
	}
}

class TaskB {
    public void solve(int testNumber, InputReader in, PrintWriter out) {
        long N = in.nextLong();
        long K = in.nextLong();

        if(N == 1) {
            out.println(0);
            return;
        }
        if(N <= K) {
            out.println(1);
            return;
        }

        long st = 1;
        long dr = K - 1;
        long m;
        long ans = -1;

        while(st <= dr) {
            m = (st + dr) / 2;

            if(get(m, K) <= N) {
                ans = m;
                st = m + 1;
            }
            else dr = m - 1;
        }

        N -= get(ans, K);

        if(ans == -1 || (ans == K - 1 && N > 0) ) {
            out.println(-1);
            return;
        }
        if(N > 0)
            ans++;

        out.println(ans);
    }

    private long get(long p, long K) {
        long sum = (K - p + 1 + K) * p / 2;
        long extra = p - 1;
        return sum - extra;
    }
}

class InputReader {
    private InputStream stream;
    private byte[] buf = new byte[1024];
    private int curChar;
    private int numChars;

    public InputReader(InputStream stream) {
        this.stream = stream;
    }

    public int read() {
        if (numChars == -1)
            throw new InputMismatchException();
        if (curChar >= numChars) {
            curChar = 0;
            try {
                numChars = stream.read(buf);
            } catch (IOException e) {
                throw new InputMismatchException();
            }
            if (numChars <= 0)
                return -1;
        }
        return buf[curChar++];
    }

    public long nextLong() {
        return Long.parseLong(nextString());
    }

    public String nextString() {
        int c = read();
        while (isSpaceChar(c))
            c = read();
        StringBuffer res = new StringBuffer();
        do {
            res.appendCodePoint(c);
            c = read();
        } while (!isSpaceChar(c));
        return res.toString();
    }

    private boolean isSpaceChar(int c) {
        return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
    }

    }
// Problem: 287_B. Pipeline
// Time complexity: logn
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

import java.util.Scanner;

/**
 *
 * @author 111
 */
public class JavaApplication4 {

    /**
     * @param args the command line arguments
     */
    static long k, n, ans;
    static private long binsearch(long l, long r)
    {
        if(l==r) return l;
        long m=(l+r)/2;
        long res=(m*(k+k-m+1)/2);
        if(res>=n)
            return binsearch(l, m);
        else
            return binsearch(m+1, r);
    }
    public static void main(String[] args) {
        Scanner in=new Scanner(System.in);
        n=in.nextLong();
        k=in.nextLong();
        n--;
        k--;
        if(k*(k+1)/2<n)
            ans=-1;
        else
            ans=binsearch(0, k);
        System.out.println(ans);            
    }
}
// Problem: 287_B. Pipeline
// Time complexity: logn
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Scanner;

public class B {

	/**
	 * @param args
	 * @throws IOException
	 * @throws NumberFormatException
	 */
	public static void main(String[] args) throws NumberFormatException,
			IOException {
		Scanner sc = new Scanner(System.in);
		long n = sc.nextLong(), k = sc.nextLong();
		// BufferedReader rd = new BufferedReader(new
		// InputStreamReader(System.in));
		// StringTokenizer t = new StringTokenizer(rd.readLine(), " ");
		// int n = Integer.parseInt(rd.readLine());
		if (n == 1) {
			System.out.println(0);
			return;
		}
		if (n <= k) {
			System.out.println(1);
			return;
		}
		long seg = (((k + 1) * (k) / 2) - 1);
		seg += (2 - k);
		if (seg < n) {
			System.out.println(-1);
			return;
		}
		// long sum = k;
		// long out = 0l;
		long s = 1, f = k;
		long mid = (s + f) / 2;
		while (s + 1 < f) {
			long seg_m = (((mid + k - 1) * (k - mid) / 2));
			// seg += (2 - mid);
			// long sum_m = seg - seg_m;
			if (seg_m >= n - 1) {
				// if (n - mid < out || out == 0) {
				// out = n - mid - 1;
				// }
				s = mid;
			} else
				f = mid;
			mid = (s + f) / 2;
		}
		// for (long i = k - 1; sum < n && i >= 2; i--) {
		// sum += i - 1;
		// out++;
		// // if (sum >= n)
		// // break;
		// }
		System.out.println(k - s);
	}
}
// Problem: 287_B. Pipeline
// Time complexity: logn


import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class PipelineRedo {
	public static void main(String[] args){
		FastScanner sc = new FastScanner();
		long n = sc.nextLong() - 1;
		long k = sc.nextInt() - 1;
		
		if(n==0){
			System.out.println(0);
			return;
		}else if(n <= k){
			System.out.println(1);
			return;
		}else if(n > k*(k+1)/2){
			System.out.println(-1);
			return;
		}
		
		//n > k, and there exists a subset (1..k) = n
		//goal : sum( subset of (1...k) ) = n
		//obs: if exists a soln, it's always possible to push everything to the right-> t + left...k
		//so that t + left...k = n, so we just have to find the smallest left such that left..k <= n
		long rightSum = k*(k+1)/2;
		long lo = 1;
		long hi = k;
		while(lo < hi){
			long mid = lo + (hi-lo+1)/2;
			long val = rightSum - mid*(mid-1)/2;
			
			if(val <= n){
				hi = mid -1;
			}else{
				lo = mid;
			}
		}
		//now lo points to the greatest left for which left..k > n
		//so lo+1 points to the smallest left for which left..k <= n
		//we still have an extra 't' to the left
		if(rightSum - (lo+1)*(lo)/2 == n){
			System.out.println(k - (lo+1) + 1);
		}else{
			System.out.println(1 + (k - (lo+1) + 1));
		}
	}
	
	public static class FastScanner {
		BufferedReader br;
		StringTokenizer st;

		public FastScanner(String s) {
			try {
				br = new BufferedReader(new FileReader(s));
			} catch (FileNotFoundException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}

		public FastScanner() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}

		String nextToken() {
			while (st == null || !st.hasMoreElements()) {
				try {
					st = new StringTokenizer(br.readLine());
				} catch (IOException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			}
			return st.nextToken();
		}

		int nextInt() {
			return Integer.parseInt(nextToken());
		}

		long nextLong() {
			return Long.parseLong(nextToken());
		}

		double nextDouble() {
			return Double.parseDouble(nextToken());
		}
	}
}
// Problem: 287_B. Pipeline
// Time complexity: logn
import java.io.*;
import java.util.*;

public class B
{
	public static void main(String [] args) throws IOException
	{
		Scanner in = new Scanner(System.in);

		long n = in.nextLong();
		long k = in.nextLong();
		if(n == 1)
		{
			System.out.println(0);
			return;
		}
		if(n <= k)
		{
			System.out.println(1);
			return;
		}

		long lb = 2, ub = k;
		long sum = ((k)*(k-1))/2;
		if(sum+1 < n)
		{
			System.out.println(-1);
			return;
		}
		while(ub - lb > 1)
		{
			long mid = (lb+ub)/2;
			long s = ((mid-1)*(mid-2))/2;
			if(n - (sum-s+1) < 0)
				lb = mid;
			else
				ub = mid;
		}

		long rem = n - (sum - ((ub-1)*(ub-2))/2 + 1);
		long res = k - ub + 1;
		if(rem == 0)
		{
			System.out.println(res);
			return;
		}
		rem++;
		if(!(rem >= 2 && rem < ub))
		{
			System.out.println(-1);
			return;
		}
		System.out.println(res+1);


	}
}
// Problem: 287_B. Pipeline
// Time complexity: logn
import java.io.InputStreamReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.PriorityQueue;
import java.util.Scanner;
import java.io.BufferedReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.InputStream;

public class palin {
	public static void main(String[] args) {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		PrintWriter out = new PrintWriter(System.out);
		Scanner scan = new Scanner(System.in);
		TaskC solver = new TaskC();
		solver.solve(1, in, out);
		out.close();
	}
}

class TaskC {
	public void solve(int testNumber, InputReader in, PrintWriter out) {
		long n = in.nextLong() - 1;
		long k = in.nextLong() - 1;
		if (n == 0) {
			out.print("0");
		} else {
			if (k >= n) {
				out.print("1");
			} else {
				if (k * (k + 1) / 2 < n) {
					out.print("-1");
				} else {
					long t = binsearch(n, k, 1, k);
					long ans = k - t + 1;
					if (k * (k + 1) / 2 - t * (t - 1) / 2 != n)
						ans++;
					System.out.println(ans);
				}
			}
		}
	}

	public static long binsearch(long n, long k, long from, long to) {
		if (from == to) {
			return from;
		}
		long mid = (from + to) / 2;
		if ((k * (k + 1)) / 2 - (mid * (mid - 1)) / 2 > n)
			return binsearch(n, k, mid + 1, to);
		else

			return binsearch(n, k, from, mid);
	}
}

class InputReader {
	BufferedReader br;
	StringTokenizer st;

	public InputReader(InputStream in) {
		br = new BufferedReader(new InputStreamReader(in));
		st = null;
	}

	public String next() {
		while (st == null || !st.hasMoreTokens()) {
			try {
				st = new StringTokenizer(br.readLine());
			} catch (IOException e) {
				throw new RuntimeException(e);
			}
		}
		return st.nextToken();
	}

	public int nextInt() {
		return Integer.parseInt(next());
	}

	public long nextLong() {
		return Long.parseLong(next());
	}
}
// Problem: 287_B. Pipeline
// Time complexity: logn
import java.io.*;
import java.math.BigInteger;
import java.util.StringTokenizer;

public class B implements Runnable {

    // leave empty to read from stdin/stdout
    private static final String TASK_NAME_FOR_IO = "";

    // file names
    private static final String FILE_IN = TASK_NAME_FOR_IO + ".in";
    private static final String FILE_OUT = TASK_NAME_FOR_IO + ".out";

    BufferedReader in;
    PrintWriter out;
    StringTokenizer tokenizer = new StringTokenizer("");

    public static void main(String[] args) {
        new Thread(new B()).start();
    }

    private void solve() throws IOException {
        long n = nextLong();
        long k = nextLong();

        n--;
        k--;
        long answer = 0;
        while (n > 0 && k >= 1) {

            if (k > 2000) {
                long step1000 = (k + (k - 999)) * 500;
                if (n - step1000 >= 0) {
                    n -= step1000;
                    answer += 1000;
                    k -= 1000;
                    continue;
                }
            }

            if (n - k >= 0) {
                n -= k;
                answer++;
            }

            k--;
            k = Math.min(n, k);
        }

        if (n == 0) {
            out.println(answer);
        } else {
            out.println(-1);
        }
    }

    public void run() {
        long timeStart = System.currentTimeMillis();

        boolean fileIO = TASK_NAME_FOR_IO.length() > 0;
        try {

            if (fileIO) {
                in = new BufferedReader(new FileReader(FILE_IN));
                out = new PrintWriter(new FileWriter(FILE_OUT));
            } else {
                in = new BufferedReader(new InputStreamReader(System.in));
                out = new PrintWriter(new OutputStreamWriter(System.out));
            }

            solve();

            in.close();
            out.close();
        } catch (IOException e) {
            throw new IllegalStateException(e);
        }
        long timeEnd = System.currentTimeMillis();

        if (fileIO) {
            System.out.println("Time spent: " + (timeEnd - timeStart) + " ms");
        }
    }

    private String nextToken() throws IOException {
        while (!tokenizer.hasMoreTokens()) {
            String line = in.readLine();
            if (line == null) {
                return null;
            }
            tokenizer = new StringTokenizer(line);
        }
        return tokenizer.nextToken();
    }

    private int nextInt() throws IOException {
        return Integer.parseInt(nextToken());
    }

    private BigInteger nextBigInt() throws IOException {
        return new BigInteger(nextToken());
    }

    private long nextLong() throws IOException {
        return Long.parseLong(nextToken());
    }

    private double nextDouble() throws IOException {
        return Double.parseDouble(nextToken());
    }

}
// Problem: 287_B. Pipeline
// Time complexity: logn
import java.math.BigInteger;
import java.util.Scanner;
public class ehsan 
{
	public static BigInteger f(BigInteger m,BigInteger n){
		BigInteger s,l;
		s=n.multiply(m.add(BigInteger.valueOf(1)));
		l=m.multiply(m.add(BigInteger.valueOf(1)));
		l=l.divide(BigInteger.valueOf(2));
		s=s.subtract(l);
		s=s.subtract(m);
		return s;
	}
	public static BigInteger bs(BigInteger a,BigInteger b,BigInteger n,BigInteger d){
		BigInteger c,e;
		c=a.add(b);
		c=c.divide(BigInteger.valueOf(2));
		e=f(c,n);
		if(e.equals(d))
			return c.add(BigInteger.valueOf(1));
		if(a.equals(b.add(BigInteger.valueOf(-1))))
			return b.add(BigInteger.valueOf(1));
		if(e.compareTo(d)>0)
			return bs(a,c,n,d);
		return bs(c,b,n,d);
	}
	public static void main(String[] args) 
	{
		Scanner sc = new Scanner(System.in);
  		BigInteger bi1 = sc.nextBigInteger();
  		BigInteger bi2 = sc.nextBigInteger();
		BigInteger i,n=bi2;
		BigInteger i2=BigInteger.valueOf(1);
		BigInteger sum=BigInteger.valueOf(0);
		if(bi1.compareTo(bi2)<0){
			System.out.println(0);
			return;
		}
		else if( bi1.compareTo(bi2) == 0 )
		{
			System.out.println(1);
			return;
		}
		bi2=((n.multiply(n.add(BigInteger.valueOf(1)))).divide(BigInteger.valueOf(2))).subtract(n.subtract(BigInteger.valueOf(1)));
		if(bi1.compareTo(bi2)>0)
			System.out.println(-1);
		else{
			System.out.println(bs(BigInteger.valueOf(0),n.add(BigInteger.valueOf(-2)),n,bi1));
		}
  }
}
// Problem: 287_B. Pipeline
// Time complexity: logn
import java.util.Scanner;


public class B {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		Pipes pipes = new Pipes();
		pipes.solve();
		pipes.print();
	}

}

class Pipes {
	
	Pipes() {
		Scanner scr = new Scanner(System.in);
		n = scr.nextLong();
		k = scr.nextLong();
	}
	
	long bs(long nb, long nk) {
		
		long left = 2;
		long ls = (nk - left + 1) * (nk + left) / 2 - (nk - left);
		long right = nk;
		long rs = nk;
		
		if (nb > ls) {
			return -1;
		}
				
		long mid = left;
		
		while (rs < ls){
			mid = (left + right)/2;
			long ms = (nk - mid + 1) * (nk + mid) / 2 - (nk - mid);
			if (nb > ms) {
				right = mid;
				rs = ms;
			}
			else if (nb < ms){
				left = mid+1;
				ls = (nk - left + 1) * (nk + left) / 2 - (nk - left);
			}
			else {
				left = mid;
				break;
			} 
			
		}
		
		return left;
		
	}
	
	void solve() {
		long nn = n;
		long kk = k; 
		ans = 0;
		long ps = 1;
		long add;
		
		if (n == 1) {
			ans = 0;
			return;
		}
		
		nn = n - (ps - 1);
		while (nn > kk){
			add = bs(nn, kk);
			if (add == -1) {
				ans = -1;
				return;
			}
			else {
				ans = ans + (kk - add + 1);
			}
						
			long addn = (kk - add + 1) * (kk + add) / 2 - (kk - add); 
			ps = ps - 1 + addn;
			if (ps == n)
				return;
			nn = nn - (ps - 1);
			kk = add - 1;
		}
		
		if (nn > 0) {
			ans++;
		}
		
	}
	
	
	void print() {
		System.out.println(ans);
	}
	
	long ans;
	long n;
	long k;
}
// Problem: 287_B. Pipeline
// Time complexity: logn
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class B {

	static long n, k;

	static long sum(long mid) {
		long tmpSum = k * (k + 1) / 2;
		long nsum = (mid - 1) * (mid) / 2;
		return tmpSum - nsum;
	}

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		PrintWriter out = new PrintWriter(System.out);
		StringTokenizer sc = new StringTokenizer(br.readLine());
		n = Long.parseLong(sc.nextToken()) - 1;
		k = Long.parseLong(sc.nextToken()) - 1;
		if (n == 0)
			out.println(0);
		else if (sum(1) < n)
			out.println(-1);
		else {
			long lo = 1;
			long hi = k;
			long mid;
			while (lo < hi) {
				mid = (lo + hi) / 2;
				long sum = sum(mid);
				if (n - sum < 0)
					lo = mid + 1;
				else if (n - sum < mid) {
					hi = mid;
				} else
					hi = mid - 1;
			}
			out.println((k - lo + 1) + (n - sum(lo) == 0 ? 0 : 1));
		}
		br.close();
		out.close();
	}
}
// Problem: 287_B. Pipeline
// Time complexity: logn
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;

public class B {
	public static BufferedReader in;
	public static PrintWriter out;

	public static void main(String[] args) throws IOException {
		in = new BufferedReader(new InputStreamReader(System.in));
		out = new PrintWriter(System.out);

		boolean showLineError = true;
		if (showLineError) {
			solve();
			out.close();
		} else {
			try {
				solve();
			} catch (Exception e) {
			} finally {
				out.close();
			}
		}

	}

	static void debug(Object... os) {
		out.println(Arrays.deepToString(os));
	}

	private static void solve() throws IOException {
		String[] line = in.readLine().split(" ");
		long n = Long.parseLong(line[0]) - 1;
		long k = Long.parseLong(line[1]) - 1;
		if (f(1, k) < n) {
			out.println(-1);
			return;
		}
		if (n == 0) {
			out.println(0);
			return;
		}
		long lo = 0l;
		long hi = k;
		while (lo + 1l < hi) {
			long m = (lo + hi) / 2l;
			long f = f(k - m + 1, k);
			if (f < n) {
				lo = m;
			} else {
				hi = m;
			}
		}
		out.println(hi);

	}

	private static long f(long lo, long hi) {
		return (lo + hi) * (hi - lo + 1l) / 2l;
	}
}