codeparrot/codecomplex huggingface dataset:
// Problem: 713_B. Searching Rectangles
// Time complexity: logn
import java.io.*;
import java.util.*;
import java.math.*;

public class B {
	public static void main(String[] args) throws IOException {

		/**/
		Scanner sc = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
		/*/
		Scanner sc = new Scanner(new BufferedReader(new InputStreamReader(new FileInputStream("src/b.in"))));
		/**/
		
		int n = sc.nextInt();
		int l1 = 1;
		int r1 = n;
		int b1 = 1;
		int t1 = n;
		int min = b1;
		int max = t1;
		while (min != max) {
			int mid = (min+max)/2;
			System.out.println("? "+l1+" "+b1+" "+r1+" "+mid);
			System.out.flush();
			if (sc.nextInt() >= 1)
				max = mid;
			else
				min = mid+1;
		}
		t1 = min;
		min = l1;
		max = r1;
		while (min != max) {
			int mid = (min+max)/2;
			System.out.println("? "+l1+" "+b1+" "+mid+" "+t1);
			System.out.flush();
			if (sc.nextInt() >= 1)
				max = mid;
			else
				min = mid+1;
		}
		r1 = min;
		min = b1;
		max = t1;
		while (min != max) {
			int mid = (min+max+1)/2;
			System.out.println("? "+l1+" "+mid+" "+r1+" "+t1);
			System.out.flush();
			if (sc.nextInt() >= 1)
				min = mid;
			else
				max = mid-1;
		}
		b1 = min;
		min = l1;
		max = r1;
		while (min != max) {
			int mid = (min+max+1)/2;
			System.out.println("? "+mid+" "+b1+" "+r1+" "+t1);
			System.out.flush();
			if (sc.nextInt() >= 1)
				min = mid;
			else
				max = mid-1;
		}
		l1 = min;
		int l2 = 1;
		int r2 = n;
		int b2 = 1;
		int t2 = n;
		min = b2;
		max = t2;
		while (min != max) {
			int mid = (min+max+1)/2;
			System.out.println("? "+l2+" "+mid+" "+r2+" "+t2);
			System.out.flush();
			if (sc.nextInt() >= 1)
				min = mid;
			else
				max = mid-1;
		}
		b2 = min;
		min = l2;
		max = r2;
		while (min != max) {
			int mid = (min+max+1)/2;
			System.out.println("? "+mid+" "+b2+" "+r2+" "+t2);
			System.out.flush();
			if (sc.nextInt() >= 1)
				min = mid;
			else
				max = mid-1;
		}
		l2 = min;
		min = b2;
		max = t2;
		while (min != max) {
			int mid = (min+max)/2;
			System.out.println("? "+l2+" "+b2+" "+r2+" "+mid);
			System.out.flush();
			if (sc.nextInt() >= 1)
				max = mid;
			else
				min = mid+1;
		}
		t2 = min;
		min = l2;
		max = r2;
		while (min != max) {
			int mid = (min+max)/2;
			System.out.println("? "+l2+" "+b2+" "+mid+" "+t2);
			System.out.flush();
			if (sc.nextInt() >= 1)
				max = mid;
			else
				min = mid+1;
		}
		r2 = min;
		System.out.println("! "+l1+" "+b1+" "+r1+" "+t1+" "+l2+" "+b2+" "+r2+" "+t2);
		System.out.flush();
	}
}
// Problem: 713_B. Searching Rectangles
// Time complexity: logn
import java.util.*;

public class B {
	
	public static void main(String[] args) {
		Scanner qwe = new Scanner(System.in);
		
		int n = qwe.nextInt();
		
		//! x11 y11 x12 y12 x21 y21 x22 y22" 
		
		
		
		int x11 = bins(true,1,2,n,qwe,true);
		int y11 = bins(true,1,2,n,qwe,false);
		int x12 = bins(false,0,1,n,qwe,true);
		int y12 = bins(false,0,1,n,qwe,false);
		int x21 = bins(true,0,1,n,qwe,true);
		int y21 = bins(true,0,1,n,qwe,false);
		int x22 = bins(false,1,2,n,qwe,true);
		int y22 = bins(false,1,2,n,qwe,false);
		
		int[] xsl = {x11,x21};
		int[] xsr = {x12,x22};
		int[] ysl = {y11,y21};
		int[] ysr = {y12,y22};
		
		
		int[] ans = new int[8];
		
		for(int xpl = 0; xpl < 2; xpl++){
			for(int xpr = 0; xpr < 2; xpr++)
				for(int ypl = 0; ypl < 2; ypl++){
					for(int ypr = 0; ypr < 2; ypr++){
						
						if(xsl[xpl] <= xsr[xpr] && xsl[1-xpl] <= xsr[1-xpr] && ysl[ypl] <= ysr[ypr] && ysl[1-ypl] <= ysr[1-ypr]){
							System.out.printf("? %d %d %d %d",xsl[xpl],ysl[ypl],xsr[xpr],ysr[ypr]);
							System.out.println();
							System.out.flush();
							int response1 = qwe.nextInt();
							
							System.out.printf("? %d %d %d %d",xsl[1-xpl],ysl[1-ypl],xsr[1-xpr],ysr[1-ypr]);
							System.out.println();
							System.out.flush();
							int response2 = qwe.nextInt();
							
							if(response1 == 1 && response2 == 1){
								ans = new int[]{xsl[xpl],ysl[ypl],xsr[xpr],ysr[ypr],xsl[1-xpl],ysl[1-ypl],xsr[1-xpr],ysr[1-ypr]};
							}
							
						}
						
						
					}
				
				
				
			}
		}
		
		
		System.out.printf("! %d %d %d %d %d %d %d %d",ans[0],ans[1],ans[2],ans[3],ans[4],ans[5],ans[6],ans[7]);
		System.out.println();
		System.out.flush();
		
		qwe.close();
	}
	
	static int bins(boolean leftbound, int small, int big, int n, Scanner qwe, boolean isx){
		
		int min = 0;
		int max = n;
		
		if(leftbound){
			min++;
			max++;
		}
		
		int y1 = 1;
		int y2 = n;
		int x1 = 1;
		int x2 = n;
		//"? x1 y1 x2 y2"
		while(min+1 < max){
			
			int med = (min+max)/2;
			if(isx){
				if(!leftbound) x2 = med;
				else x1 = med;
			}
			else{
				if(!leftbound) y2 = med;
				else y1 = med;
			}
			
			System.out.printf("? %d %d %d %d",x1,y1,x2,y2);
			System.out.println();
			System.out.flush();
			
			int response = qwe.nextInt();
			if(leftbound){
				if(response >= big) min = med;
				else max= med;
			}
			else{
				if(response < big){
					min = med;
				}
				else{
					max = med;
				}
			}
		}
		
		if(leftbound) max--;
		
		return max;
		
	}

}
// Problem: 713_B. Searching Rectangles
// Time complexity: logn
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.PriorityQueue;
import java.util.StringTokenizer;

public class Solution {
	static BufferedReader br;
	static int[] ans;
	public static void main(String[] args) throws Exception{
		br = new BufferedReader(new InputStreamReader(System.in));
		ans = new int[8];
		int n = Integer.parseInt(br.readLine());
		System.out.println("?"+"1 1 "+n+" "+n);
		System.out.flush();
		int q = Integer.parseInt(br.readLine());
		cut(n);
		System.out.print("! ");
		for(int i=0 ; i<8 ; i++)	System.out.print(ans[i]+" ");
		System.out.println();
	}
	
	public static void solve(int x1, int y1, int x2, int y2, int t) throws Exception{
		int l=x1, r=x2;
		int xx1,yy1,xx2,yy2;
		while(l<r){
			int mid = (l+r)/2;
			if(query(x1,y1,mid,y2)==1)	r=mid;
			else	l=mid+1;
		}
		xx2 = l;
		l=x1; r=x2;
		while(r>l){
			int mid = (l+r+1)/2;
			if(query(mid,y1,x2,y2)==1)	l = mid;
			else r=mid-1;
		}
		xx1 = l;
		l=y1; r=y2;
		while(l<r){
			int mid = (l+r)/2;
			if(query(x1,y1,x2,mid)==1)	r=mid;
			else	l=mid+1;
		}
		yy2=l;
		l=y1;r=y2;
		while(r>l){
			int mid = (l+r+1)/2;
			if(query(x1,mid,x2,y2)==1)	l=mid;
			else	r=mid-1;
		}
		yy1 = l;
		ans[t] = xx1;	ans[t+1] = yy1 ; ans[t+2] = xx2;	ans[t+3] = yy2;
	//	System.out.println("!"+xx1+" "+yy1+" "+xx2+" "+yy2);
	}
	public static void cut(int n) throws Exception{
		int l=1, r=n;
		while(l<r){
			int mid = (l+r)/2;
			if(query(1,1,n,mid)==0)	l=mid+1;
			else	r = mid;
		}
		if(query(1,1,n,l)==1 && query(1,l+1,n,n)==1){
			solve(1,1,n,l,0);
			solve(1,l+1,n,n,4);
			return;
		}
		l=1;r=n;
		while(l<r){
			int mid = (l+r)/2;
			if(query(1,1,mid,n)==0)	l=mid+1;
			else	r=mid;
		}
		solve(1,1,l,n,0);
		solve(l+1,1,n,n,4);
	}
	public static int query(int x1, int y1, int x2, int y2) throws Exception{
		System.out.println("?"+x1+" "+y1+" "+x2+" "+y2);
		System.out.flush();
		int q = Integer.parseInt(br.readLine());
		return q;
	}
}
// Problem: 287_B. Pipeline
// Time complexity: logn
import java.util.*;
import java.io.*;

public class Main {

	BufferedReader in;
	StringTokenizer str = null;
	PrintWriter out;
	
	private String next() throws Exception{
		if (str == null || !str.hasMoreElements())
			str = new StringTokenizer(in.readLine());
		return str.nextToken();
	}
	
	private int nextInt() throws Exception{
		return Integer.parseInt(next());
	}
	
	private long nextLong() throws Exception{
		return Long.parseLong(next());
	}
	
	private double nextDouble() throws Exception{
		return Double.parseDouble(next());
	}
	
	public void run() throws Exception{
		in =  new BufferedReader(new InputStreamReader(System.in));
		out = new PrintWriter(System.out);

		long n = nextLong();
		if (n == 1) {
			System.out.println(0);
			return;
		}
		long k = nextLong();
		long t = 1-(k-1) + k*(k+1)/2-1;
		if (t < n){
			System.out.println(-1);
			return;
		}

		long l = 0;
		long r = k;

		while(r - l > 1) {
			long m = (r + l)/2;
			long s = 1 - m + k*(k+1)/2 - (k-m)*(k-m+1)/2;
			//System.out.println(m + " " + s + " " + n);
			if (s >= n){
				r = m;
			}else{
				l = m;
			}
		}
		System.out.println(r);
		out.close();
	}
		
	public static void main(String[] args) throws Exception{
		new Main().run();
	}
}
// Problem: 287_B. Pipeline
// Time complexity: logn
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 ((k - 1) * k / 2 + 1 < n) {
			System.out.println(-1);
			return;
		}
		long left = 0;
		long right = k;
		while (left < right) {
			long m = (left + right) / 2;
			if (k * (k - 1)/2 - (k - m) * (k - m - 1) / 2 +1 < n)
				left = m + 1;
			else
				right = m;
		}
		System.out.println(left);
	}
}
// Problem: 287_B. Pipeline
// Time complexity: logn
import java.util.*;

public class B {
	static long sum(long from, long to){
		final long d = to - from;
		return (d*(d + 1))/2 + (d + 1)*from;
	}
	static long howMany(long n, long k){
		if (n == 1){
			return 0;
		}
		if (n > (k*(k - 1))/2 + 1){
			return -1;
		}
		long hi = k - 1;
		long lo = 1;
		while (lo < hi){
			final long mi = (lo + hi + 1) >> 1;
			final long sum = sum(mi, k - 1);
			if (n - 1 - sum < mi){
				lo = mi;
			}else{
				hi = mi - 1;
			}
		}
		long res = k - lo;
		final long sum = sum(lo, k - 1);
		if (n - 1 - sum > 0){
			res++;
		}
		return res;
	}
	public static void main(String [] args){
		try (Scanner s = new Scanner(System.in)){
			final long n = s.nextLong();
			final long k = s.nextLong();
			System.out.println(howMany(n, k));
		}
	}
}
// Problem: 287_B. Pipeline
// Time complexity: logn
import java.io.*;
import java.math.BigInteger;
import java.util.*;

public class Main {
	public static void main(String[] args) throws IOException {
		(new Main()).solve();
	}

	public Main() {
	}
	
	MyReader in = new MyReader();
	PrintWriter out = new PrintWriter(System.out);
	
	void solve() throws IOException {
		// BufferedReader in = new BufferedReader(new
		// InputStreamReader(System.in));
		// Scanner in = new Scanner(System.in);

		//Scanner in = new Scanner(new FileReader("forbidden-triples.in"));
		//PrintWriter out = new PrintWriter("forbidden-triples.out");
		long n = in.nextLong();
		long k = in.nextLong();
		long sum = 1;
		long count = 0;
		
		long index = k - 1;
		
		long[] delta = {1000000000, 100000000, 10000000, 1000000, 100000, 10000, 1000, 100, 10, 1, 0};
		
		while (index > 0) {
			if (index + sum <= n) {
				for (int d = 0; d < delta.length; d++) {
					if (delta[d] < index) {
						long m = (2 * index - delta[d])*(delta[d] + 1)/2;
						if (m + sum <= n) {
							sum += m;
							index -= (delta[d] + 1);
							count += (delta[d] + 1);
						}
					}
				}
			} else {
				index = n - sum;
			}
		}
		if (sum == n) {
			out.println(count);
		} else {
			out.println(-1);
		}
		
		
		out.close();
	}	

};

class MyReader {
	private BufferedReader in;
	String[] parsed;
	int index = 0;

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

	public int nextInt() throws NumberFormatException, IOException {
		if (parsed == null || parsed.length == index) {
			read();
		}
		return Integer.parseInt(parsed[index++]);
	}

	public long nextLong() throws NumberFormatException, IOException {
		if (parsed == null || parsed.length == index) {
			read();
		}
		return Long.parseLong(parsed[index++]);
	}
	
	public String nextString() throws IOException {
		if (parsed == null || parsed.length == index) {
			read();
		}
		return parsed[index++];
	}

	private void read() throws IOException {
		parsed = in.readLine().split(" ");
		index = 0;
	}

	public String readLine() throws IOException {
		return in.readLine();
	}
};
// Problem: 287_B. Pipeline
// Time complexity: logn
import java.io.PrintWriter;
import java.util.Scanner;

public class Problem2 implements Runnable {
    public void run() {
        Scanner scanner = new Scanner(System.in);
        PrintWriter writer = new PrintWriter(System.out);

        long n = scanner.nextLong();
        long k = scanner.nextLong();

        long count = 1;


        if (n == 1) {
            writer.println(0);
            writer.close();
            return;
        }

        if (k >= n) {
            writer.println(1);
            writer.close();
            return;
        }

        long answer = 0;

        while (k > 1) {
            if (k > 2000) {
                if (count + k <= n) {
                    if (count + (k - 1 + k - 1000) * 500 <= n) {
                        count += (k - 1 + k - 1000) * 500;
                        k -= 1000;
                        answer += 1000;
                    }
                }
            }
            if ((count + k - 1) <= n) {
                    count += (k - 1);
                    answer++;

            }

            if (count + k - 100000000000000000l > n) {
                k -= 99999999999999999l;
            }
            if (count + k - 10000000000000000l > n) {
                k -= 9999999999999999l;
            }
            if (count + k - 1000000000000000l > n) {
                k -= 999999999999999l;
            }
            if (count + k - 100000000000000l > n) {
                k -= 99999999999999l;
            }
            if (count + k - 10000000000000l > n) {
                k -= 9999999999999l;
            }
            if (count + k - 1000000000000l > n) {
                k -= 999999999999l;
            }
            if (count + k - 100000000000l > n) {
                k -= 99999999999l;
            }
            if (count + k - 10000000000l > n) {
                k -= 9999999999l;
            }
            if (count + k - 1000000000l > n) {
                k -= 999999999l;
            }
            if (count + k - 100000000l > n) {
                k -= 99999999l;
            }
            if (count + k - 10000000l > n) {
                k -= 9999999l;
            }
            if (count + k - 1000000l > n) {
                k -= 999999l;
            }
            if (count + k - 100000l > n) {
                k -= 99999l;
            }
            if (count + k - 10000l > n) {
                k -= 9999l;
            }
            if (count + k - 1000l > n) {
                k -= 999l;
            }
            if (count + k - 100l > n) {
                k -= 99l;
            }


            if (n - count + 1 < k) {
                k = n - count + 1;
            } else {
                k--;
            }

        }


        if (count == n) {
            writer.println(answer);
        } else {
            writer.println(-1);
        }
        writer.close();
    }
    public static void main(String[] args) {
        new Problem2().run();
    }
}
// Problem: 287_B. Pipeline
// Time complexity: logn
import java.io.*;
import java.util.*;

public class My {
  public static void main(String[] args) {
    new My().go();
  }

  
  void go() {
    Scanner in = new Scanner(System.in);
    long n = in.nextLong();
    int k = in.nextInt();
    int mn = 0, mx = k + 1;
    while (mn < mx) {
      int mid = (mn + mx) / 2;
      if (works(n, k, mid)) {
        mx = mid;
      } else {
        mn = mid + 1;
      }
    }
    if (mn > k) {
      pl("-1");
    } else {
      pl((mn - 1) + "");
    }
  }
  
  boolean works(long n, int k, int use) {
    return 1 + T(k - 1) - T(k - use) >= n;
  }
  
  long T(int n) {
    return n * (long)(n + 1) / 2;
  }
  
  void p(String s) {
    System.out.print(s);
  }

  void pl(String s) {
    System.out.println(s);
  }
}
// Problem: 287_B. Pipeline
// Time complexity: logn
import java.io.PrintWriter;
import java.util.*;

public class B {

	public static void main(String[] args) {
		PrintWriter out = new PrintWriter(System.out);
		Scanner sc = new Scanner(System.in);

		long N = sc.nextLong();
		long K = sc.nextLong();

		if (N == 1) {
			out.println(0);
		} else if (N <= K) {
			out.println(1);
		} else if (N > ((K - 1) * (K)) / 2 + 1) {
			out.println(-1);
		} else {

			long lo = 1;
			long hi = Math.max(K - 2, 1);

			long big = ((K - 2) * (K - 1)) / 2;

			long prevmid = -1;

			for (int i = 0; i < 10000; i++) {
				long mid = (lo + hi) / 2;

				// K = 5
				// Start = K-2;
				// 1 = K-2;
				// 2 = K-3... etc.

				long tmp = ((K - 2 - mid) * (K - 2 - mid + 1)) / 2;
				//System.out.println(mid + " " + big + " " + tmp);

				if (K + big - tmp > N) {
					hi = mid;
				} else if (K + big - tmp < N) {
					lo = mid;
					if (prevmid == mid)
						lo++;
					lo = Math.min(lo, hi);
					prevmid = mid;
				} else {
					lo = mid;
					break;
				}
			}
			out.println((long) lo + 1);
		}
		sc.close();
		out.close();
	}
}
// Problem: 287_B. Pipeline
// Time complexity: logn
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Scanner;
import java.util.Vector;

/**
 * Created with IntelliJ IDEA.
 * User: horikawa
 * Date: 3/23/13
 * Time: 1:29 AM
 * To change this template use File | Settings | File Templates.
 */
public class B {
    public static void main (String[] argv) {
        Scanner in = new Scanner(System.in);
        long n = in.nextLong();
        long k = in.nextLong();
        long max = ((k*(k-1))/2L)+1L;
        long ans = -1;
        if (n == 1) {
            System.out.println(0);
            return;
        }
        if (max < n) {
            ans = -1;
        } else if (max == n) {
            ans = k-1;
        } else {
            if (k >= n) {
                ans = 1;
            } else {
                long low = 1;
                long high = k-1;
                while (high > low+1) {
                    long mid = (low+high)/2;
                    long sum = (((mid+(k-1)) * (k-mid)) / 2) + 1;
                    if (sum >= n) {
                        low = mid;
                    } else {
                        high = mid;
                    }
                }
                ans = (k - low);
            }
        }
        System.out.println(ans);
        return;
    }
}
// Problem: 287_B. Pipeline
// Time complexity: logn
import java.io.PrintWriter;
import java.util.Scanner;

public class B {

	public static void main(String[] args) {
		doIt();
	}

	static void doIt() {
		Scanner sc = new Scanner(System.in);
		PrintWriter pw = new PrintWriter(System.out);
		long n = sc.nextLong();
		long k = sc.nextLong();
		long msum = (k - 1) * k / 2 + 1;
		long u = k;
		long l = 0;
		long m = (u + l) / 2;
		while(l < u){
			m = (u + l) / 2 + (u + l) % 2;
			long sum = (m - 1) * m / 2;
			if(n <= msum - sum) l = m;
			else u = m - 1;
		}
		m = (u + l) / 2 + (u + l) % 2;
		if(msum - (m - 1) * m / 2 < n) System.out.println(-1);
		else System.out.println(k - m);
	}
}
// Problem: 287_B. Pipeline
// Time complexity: logn
import java.util.Scanner;
import java.io.OutputStream;
import java.io.IOException;
import java.io.PrintWriter;
import java.io.InputStream;

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

class TaskB {
    public void solve(int testNumber, Scanner in, PrintWriter out) {
        long n=in.nextLong();
        long k=in.nextInt();
        if(n==1){
            out.println(0);
            return;
        }
        long max=k*(k-1)/2+1;
        if(max<n){
            out.println("-1");
            return;
        }

        long low=1,high=k-1;
        long ans=k-1;
        while (low<=high){
            long mid=(low+high)/2;
            long val=mid*mid-mid*(2*k-1)+2*n-2;
            if(val>0){
                low=mid+1;
            }
            else {
                ans=mid;
                high=mid-1;
            }
        }
        out.println(ans);

    }
}
// Problem: 287_B. Pipeline
// Time complexity: logn
import java.util.*;
import java.lang.*;
import java.math.*;
import java.io.*;
import static java.lang.Math.*;
import static java.util.Arrays.*;
import static java.util.Collections.*;

public class P287B{
	Scanner sc=new Scanner(System.in);

	int INF=1<<28;
	double EPS=1e-9;

	long n, k;

	void run(){
		n=sc.nextLong();
		k=sc.nextLong();
		solve();
	}

	void solve(){
		long left=-1, right=k+1;
		for(; right-left>1;){
			long m=(left+right)/2;
			long lb=k*(k+1)/2-(k-m)*(k-m+1)/2-(m-1);
			if(lb>=n){
				right=m;
			}else{
				left=m;
			}
		}
//		debug(left, right);
		println(""+(right>k?-1:right));
	}

	void println(String s){
		System.out.println(s);
	}

	void print(String s){
		System.out.print(s);
	}

	void debug(Object... os){
		System.err.println(deepToString(os));
	}

	public static void main(String[] args){
		Locale.setDefault(Locale.US);
		new P287B().run();
	}
}
// Problem: 287_B. Pipeline
// Time complexity: logn
/**
 * Created with IntelliJ IDEA.
 * User: yuantian
 * Date: 3/24/13
 * Time: 2:18 AM
 * Copyright (c) 2013 All Right Reserved, http://github.com/tyuan73
 */

import java.util.*;

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

        long n = in.nextLong();
        long k = in.nextLong();

        if (n == 1) {
            System.out.println(0);
            return;
        }
        if (k >= n) {
            System.out.println(1);
            return;
        }

        long total = (k + 2) * (k - 1) / 2 - (k - 2);
        if (total < n) {
            System.out.println(-1);
            return;
        }

        int i = 2, j = (int) k;
        while (i <= j) {
            int m = (i + j) / 2;
            total = (k + m) * (k - m + 1) / 2 - (k - m);
            if (total == n) {
                System.out.println(k - m + 1);
                return;
            }
            if (total < n)
                j = m - 1;
            else
                i = m + 1;
        }
        System.out.println(k-i+2);
    }
}
// Problem: 287_B. Pipeline
// Time complexity: logn
import java.util.Scanner;

public class b {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long n = sc.nextLong() - 1, k = sc.nextLong() - 1;

        int a = 0;
        if ((k + 1) * k / 2 < n) {
            System.out.println(-1);
            return;
        }
        while (n > 0 && k > 0) {
            long min = go(n, k);
            a += (k - min + 1);
            n -= (k + min) * (k - min + 1) / 2;
            k = Math.min(min - 1, n);
        }

        if (n == 0)
            System.out.println(a);
        else
            System.out.println(-1);

    }

    static long go(long n, long k) {
        long low = 1, high = k;

        while (low + 1 < high) {
            long mid = (low + high) / 2;

            if ((k + mid) * (k - mid + 1) / 2 <= n) {
                high = mid;
            } else
                low = mid;

        }
        return high;
    }

}
// Problem: 287_B. Pipeline
// Time complexity: logn
import java.util.Scanner;

public class Pipeline {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long n = sc.nextLong();
		long k = sc.nextLong();
		sc.close();

		if (k * (k - 1) / 2 + 1 < n) {
			System.out.println(-1);
		} else {
			long l = -1, r = k;
			while (r - l > 1) {
				long m = (r + l) / 2;
				if (cantidadPosible(k, m) >= n) {
					r = m;
				} else {
					l = m;
				}
			}
			System.out.println(r);
		}

	}

	private static long cantidadPosible(long k, long usadas) {
		return (k * (k - 1) / 2 + 1 - (k - usadas) * (k - usadas - 1) / 2);
	}
}