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

//package pipeline;

import java.util.Scanner;

/**
 *
 * @author admin
 */
public class Main {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        // TODO code application logic here
        Scanner scan=new Scanner(System.in);
        long n=scan.nextLong(),k=scan.nextLong();
        if(n>((k-2)*(k-1))/2+k){
            System.out.println("-1");
        }
 else if(n==1){
            System.out.println("0");

 }
 else if(n<=k&&n>1){
            System.out.println("1");
 }
 else{
            n-=k;
            long start=k-2;
            long x;
            long left=1,right=k-2;
           // System.out.println(left+" "+right);
            while(left<=right){
            x=(left+right)/2;
            //    System.out.println(x);
                
            if(n>cumSum(x, start)){
            left=x+1;
          //  System.out.println("if");
            }
 else if(n<cumSum(x-1, start)){
 right=x-1;
            //    System.out.println("else if");
 }
 else{
                System.out.println(1+x);
                break;
 }
            }


 }

    }
    public static long cumSum(long x,long start){
    return (x*(2*start+1-x))/2;
    }

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

public class Solution {
    public static void main (String[] args) throws IOException {
        boolean online = "true".equals(System.getProperty("ONLINE_JUDGE"));
        if (online) {
            in = new InputReader(new InputStreamReader(System.in));
            out = new PrintWriter(System.out);
        }
        else {
            in = new InputReader(new FileReader("input.txt"));
            out = new PrintWriter(new File("output.txt"));
        }
        
        new Solution().run();
        
        out.close();
    }
    
    long sum (int x) {
        return x * 1l * (x+1) / 2;
    }
    
    int bins (long n, int k) {
        int l = 1,
            r = k;
        while (l < r) {
            int w = (l+r)/2;
            long s = sum(k) - sum(w-1);
            if (s == n)
                return w;
            if (s < n)
                r = w;
            else
                l = w+1;
        }
        return l;
    }
    
    private void run () {
        long n = in.nextLong();
        int k = in.nextInt();
        if (n == 1) {
            out.println(0);
            return;
        }
        if (1 + sum(k-1) < n) {
            out.println(-1);
            return;
        }
        int c = bins(n-1,k-1);
        if (1 + sum(k-1) - sum(c-1) == n)
            out.println(k-c);
        else
            out.println(k-c+1);
    }
    
    private static InputReader in;
    private static PrintWriter out;
}

class InputReader {
    public InputReader (Reader r) {
        buff = new BufferedReader(r);
        try {
            str = new StringTokenizer(buff.readLine());
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    
    public String next () {
        while (!str.hasMoreTokens())
            try {
                str = new StringTokenizer(buff.readLine());
            } catch (IOException e) {
                e.printStackTrace();
            }
        return str.nextToken();
    }
    
    public int nextInt () {
        return Integer.parseInt(this.next());
    }
    
    public long nextLong () {
        return Long.parseLong(this.next());
    }
    
    private static BufferedReader buff;
    private static StringTokenizer str;
}
// Problem: 287_B. Pipeline
// Time complexity: logn
import java.util.*;
import java.math.*;
import java.io.*;

public class Main
    {
    public static void main(String args[]) throws IOException
        {
        Scanner c=new Scanner(System.in);
        PrintWriter out=new PrintWriter(System.out);
        long N=c.nextLong()-1;
        long K=c.nextLong()-1;
        long tot=(K*(K+1))/2;
        //System.out.println(tot);
        if(N>tot)
            {
            System.out.println(-1);
            return;
            }
        long lo=1;
        long hi=K;
        while(hi-lo>=10)
            {
            long mid=(hi+lo)/2;
            //maximum outlets using mid pipes
            long sum=(mid*(mid-1))/2;
            long left=mid*K-sum;
            if(left>=N)
                hi=mid+1;
            else
                lo=mid-1;
            }
        for(int num=(int)lo-1000;num<lo+1000;num++)
            {
            if(num>=0)
                {
                long sum=((long)num*(num-1))/2;
                long left=(long)num*K-sum;
                if(left>=N)
                    {
                    System.out.println(num);
                    return;
                    }
                }
            }
        out.close();
        }
    }

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

    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 int readInt()
        {
        int c=read();
        while (isSpaceChar(c))
            c=read();
        int sgn=1;
        if(c=='-')
            {
            sgn=-1;
            c=read();
            }
        int res=0;
        do
            {
            if(c<'0'||c>'9')
                throw new InputMismatchException();
            res*=10;
            res+=c-'0';
            c=read();
            } while (!isSpaceChar(c));
        return res*sgn;
        }

    public boolean isSpaceChar(int c)
        {
        if(filter!=null)
            return filter.isSpaceChar(c);
        return isWhitespace(c);
        }

    public static boolean isWhitespace(int c)
        {
        return c==' '||c=='\n'||c=='\r'||c=='\t'||c==-1;
        }

    public char readCharacter()
        {
        int c=read();
        while (isSpaceChar(c))
            c=read();
        return (char) c;
        }

    public interface SpaceCharFilter
        {
        public boolean isSpaceChar(int ch);
        }
    }
// Problem: 287_B. Pipeline
// Time complexity: logn
import java.util.*;
import java.math.*;
public class B2 {

    /**
     * @param args
     */
    public static void main(String[] args) {
        // TODO Auto-generated method stub
        Scanner scan = new Scanner(System.in);
        BigInteger n = new BigInteger(scan.next());
        BigInteger k = new BigInteger(scan.next());
        BigInteger a = k.subtract(bi(1));
        BigInteger lim = k.multiply(a).divide(bi(2));
        lim = lim.add(bi(1));
        //System.out.println("lim: "+lim);
        if (n.compareTo(lim)>0){
            System.out.println(-1);
        }
        else {
            if (n.equals(1)){
                System.out.println(0);
            }
            else {
                BigInteger remain2 = lim.subtract(n).add(bi(1));
                remain2 = remain2.multiply(bi(2));
                //System.out.println(remain2);
                double temp = remain2.doubleValue();
                //System.out.println(temp);
                long flr = (long)Math.sqrt(temp);
                //System.out.println(flr);
                BigInteger flr2 = bi(flr);
                BigInteger rnd2 = remain2.subtract(flr2.multiply(flr2));
                long rnd = remain2.longValue()-flr*flr;
                //System.out.println("rnd "+rnd);
                /*
                if (rnd<=flr){
                    System.out.println(k.intValue()-flr);
                }
                else {
                    System.out.println(k.intValue()-(flr+1));
                }
                */
                if (rnd2.compareTo(flr2)<=0){
                    System.out.println(k.subtract(flr2) );
                }
                else {
                    System.out.println(k.subtract(flr2.add(bi(1) ) ) );
                }
            }
        }
    }
    public static BigInteger bi(int n1){
        return new BigInteger(""+n1);
    }
    public static BigInteger bi(long n1){
        return new BigInteger(""+n1);
    }

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

import java.util.Scanner;

public class B2 {
	public static void main (String args[]){
		Scanner in = new Scanner(System.in);
		long n = in.nextLong();
		long k = in.nextLong();
		long upn = k;
		long tmp=upn;
		if(n==1){
			System.out.println(0);
			return;
		}
		if(n<=k){
			System.out.println(1);
			return;
		}
		//---
		if(!bS(n, k, upn)){
			System.out.println(-1);
			return;
		}
		boolean flag = false;
			while(bS(n, k, upn)){
				tmp = upn;
				flag = true;
				upn=5*upn/6;
				if(tmp==upn)
					break;
			}
			long ans = tmp;
			if(!flag)
				upn=0;
			for(int i = (int)tmp;i>=upn;i--){
				if(bS(n, k, i)){
					ans=i;
				}
				else
					break;
			}
			System.out.println(ans);
	}
	
	static boolean bS(long key,long k ,long n) 
	    {
		long pipe = (n * (k-n+k+1))/2;
		pipe = pipe - n+1;
	         if(pipe>=key){
	        	 return true;
	         }
	         else
	        	 return false;
	   }
}
// Problem: 287_B. Pipeline
// Time complexity: logn
import java.io.*;
import java.util.*;

public class Main
{
	long sum ( long n ) { return (n*(n+1))/2; }

	public void solve ( ) throws Exception
	{
		Scanner in = new Scanner ( System.in );
		long n = in.nextLong()-1;
		long k = in.nextLong()-1;
		
		long lo = 0, hi = k, mi;
		while ( lo < hi )
		{
			mi = ( lo + hi ) / 2;
			if ( sum(k)-sum(k-mi-1) <= n ) lo = mi+1;
			else hi = mi;
		}
		
		long ans = lo;
		n -= ( sum(k) - sum(k-ans) );
		k -= ans;

		if ( n > k ) println ( "-1" );
		else if ( n == 0 ) println ( ans );
		else println ( (ans+1) );
	}
	
	public static void main ( String[] args ) throws Exception { (new Main()).solve(); }
	public static void print ( Object o ) { System.out.print ( o ); }
	public static void println ( Object o ) { System.out.println ( o ); }
	public static void println ( ) { System.out.println ( ); }
}
// 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
 * @author dy
 */
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();
        int K = in.nextInt();
        long pipes = 1;
        if(N == 1){
            out.println(0);return;
        }
        long left = 0, right = K - 1, find = -1;
        while (left <= right){
            long mid = (left + right) / 2;
            if(mid * mid + (1 - 2 * K) * mid + 2 * (N - 1) <= 0){
                find = mid;
                right = mid - 1;
            }
            else
                left = mid + 1;
        }
        out.println(find);
    }
}
// Problem: 287_B. Pipeline
// Time complexity: logn
import java.util.Scanner;

public class B{
    public static void main(String args[]){
        Scanner input = new Scanner(System.in);
        long n = input.nextLong();
        long k = input.nextLong();
        System.out.println(solve(n, k));
        input.close();
    }
    
    public static long solve(long n, long k){
        long dis = n - k;
        if(n == 1)
            return 0;
        if((((k - 2) * ((k - 2) + 1)) / 2) + 1 <= dis)
            return -1;
        if(k >= n)
            return 1;
        //
        long ans = 2;
        long now = (((k - 2) * ((k - 2) + 1)) / 2) + 1 + k;
        long dist = Math.abs(now - n);
        long delta = 1 + 8 * dist;
        double ret = (1 + Math.sqrt(delta)) / 2;
        //
        now = (((k - 2) * ((k - 2) + 1)) / 2) + 1 + k;
        dist = Math.abs(now - k);
        delta = 1 + 8 * dist;
        double nret = (1 + Math.sqrt(delta)) / 2;
        //
        double back = nret - ret;
        ans = (long) back;
        return ans + 2;
    }
}
// Problem: 287_B. Pipeline
// Time complexity: logn
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s = sc.nextLine();
        String[] info = s.split(" ");
        long n = Long.parseLong(info[0]);
        long k = Long.parseLong(info[1]);
        sc.close();

        long maximum = k * (k - 1) / 2 + 1;
        if (n == 1)
            System.out.println(0);
        else if (n > maximum)
            System.out.println(-1);
        else {
            long left = 0, right = k - 1;
            while (left + 1 < right) {
                long mid = (right + left) / 2;
                if (mid * (k - 1 + k - mid) / 2 + 1 >= n)
                    right = mid;
                else
                    left = mid;
            }
            System.out.println(right);
        }
    }
}
// Problem: 287_B. Pipeline
// Time complexity: logn
import java.io.*;
import java.util.*;

public class SolutionB {
   BufferedReader in;
   StringTokenizer str;
   PrintWriter out;
   String SK;
   String next() throws IOException {
      while ((str == null) || (!str.hasMoreTokens())) {
         SK = in.readLine();
         if (SK == null)
              return null;
         str = new StringTokenizer(SK);
      }
      return str.nextToken();
   }
   int nextInt() throws IOException {
      return Integer.parseInt(next());
   }
   double nextDouble() throws IOException {
      return Double.parseDouble(next());
   }
   long nextLong() throws IOException {
      return Long.parseLong(next());
   }
   char[] charArray() throws IOException{
      return next().toCharArray();
   }
   public static void main(String[] args) throws IOException {
      new SolutionB().run();
   }
   void run() throws IOException {
      in = new BufferedReader(new InputStreamReader(System.in));
      out = new PrintWriter(System.out);
      //in = new BufferedReader(new FileReader("input.txt"));
      //out = new PrintWriter("output.txt");
      solve();
      out.close();
   }
   void solve() throws IOException {
      //out.println(Long.MAX_VALUE);
      long n = nextLong();
      long k = nextLong();
      long m=num1(k);
      if(m<n){
         out.println(-1);
         return;
      }
      if(m==n){
         out.println(k-1);
         return;
      }
      long ans=binS(n,k);
      out.println(k-ans);
   }
   long num1(long k){
      long r=k*(k+1)/2-1;
      r=r-(k-2);
      return r;
   }
   long num2(long k){
      return num1(k)-1;
   }
   long binS(long n, long k) {
      long start, end, mid;
      start = 2;
      end = k;
      long ret=-1;
      while (start <= end) {
         mid = (start + end) / 2;
         if (num1(k)-num2(mid) == n) {
            return mid;
         } else if (num1(k)-num2(mid) < n) {
            end = mid - 1;
         } else {
            ret=mid;
            start = mid + 1;
         }
      }
      return ret;
   }
}
// Problem: 287_B. Pipeline
// Time complexity: logn

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

public class TaskB {
    static BufferedReader in = new BufferedReader(new InputStreamReader(
            System.in));
    static StringTokenizer str;
    static String SK;

    static String next() throws IOException {
        while ((str == null) || (!str.hasMoreTokens())) {
            SK = in.readLine();
            if (SK == null)
                return null;
            str = new StringTokenizer(SK);
        }
        return str.nextToken();
    }

    static int nextInt() throws IOException {
        return Integer.parseInt(next());
    }

    static long nextLong() throws IOException {
        return Long.parseLong(next());
    }

    static double nextDouble() throws IOException {
        return Double.parseDouble(next());
    }

    public static void main(String[] args) throws IOException {
        long n = nextLong();
        int k = nextInt();
        if (n == 1) {
            System.out.println(0);
            return;
        }
        long sum = (((2 + (long) k)) * ((long) k - 1)) / 2 - ((long) k - 2);
        if (n > sum) {
            System.out.println(-1);
            return;
        } else if (n <= k) {
            System.out.println(1);
            return;
        }

        long cnt = 0;
        long sum2 = 0;
        int index = binSearch(2, k, k, n);

        sum2 = (((long) (index) + k) * (long) (k - index + 1)) / 2 - (long) (k - index);
        cnt = k - index + 1;
        if (sum2 == n) {
            System.out.println(cnt);
            return;
        }
        if (sum2 > n)
            for (int kk = index; kk <= k; kk++) {
                sum2 = (((long) (kk) + k) * (long) (k - kk + 1)) / 2 - (long) (k - kk);
                cnt--;
                if (sum2 <= n) {
                    System.out.println(cnt + 1);
                    return;
                }
            }
        else {
            for (int kk = index - 1; kk >= 2; kk--) {
                sum2 = (((long) (kk) + k) * (long) (k - kk + 1)) / 2 - (long) (k - kk);
                cnt++;
                if (sum2 >= n) {
                    System.out.println(cnt);
                    return;
                }
            }
        }
        System.out.println(-1);
        return;
    }

    static int binSearch(int l, int r, int k, long n) {
        while (true) {
            int mid = l + (r - l) / 2;
            long sum2 = (((long) (mid) + k) * (long) (k - mid + 1)) / 2 - (long) (k - mid);
            if (l >= r || sum2 == n) {
                return mid;
            } else if (sum2 > n) {
                l = mid + 1;
            } else if (sum2 < n) {
                r = mid;
            }
        }
    }
}
// Problem: 287_B. Pipeline
// Time complexity: logn
import java.util.*;
import java.io.*;

public class Contest176B {
    public static void main(String[] args) throws IOException{
        Scanner sc = new Scanner(System.in);
        long n = sc.nextLong();
        int k = sc.nextInt();
        
        if( ((long)k * (long)(k + 1))/2 - 1 - (k - 2) < n){
            System.out.println(-1);
            return;
        }
        
        if(n == 1) {
            System.out.println(0);
            return;
        }
        
        if(n <= k) {
            System.out.println(1);
            return;
            
        }
        
        int ans = rek(2, k, n, k);
        
        System.out.println(ans);
    }
    
    private static int rek(int s, int e, long n, int k){
        //System.out.println(s + " " + e );
        if(s == e){
            return k - s + 1;
        }
        if(s + 1 == e){
            if(sum(e, k) >= n) return k - e + 1;
            return k - s + 1;
        }

        int m = (s + e)/2;
        
        long ans = sum(m, k);
        
        if(ans == n) return k - m + 1;
        if(ans < n) return rek(s, m - 1, n, k);
        else return rek(m , e, n, k); 
        
        
    }
    private static long sum(int a, int b ){
        long sum1 = ((long)a * (long)(a - 1))/2;
        long sum2 = ((long)b * (long)(b + 1))/2;
        int numelement = b - a + 1;
        
        return sum2 - sum1 - (numelement - 1);
    }
    

    
}
// 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
 * @author Saul
 */
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() ;
    int k = in.nextInt();
    long top = 1L * k * (k+1) / 2L - k + 1;

    if ( n == 1L ){
      out.print(0);
      return;
    }

    if ( n > top ){
      out.print(-1);
      return;
    }

    int ans = 0;
    if ( n > 0 ){
      ++ans;
      n -= k;
      k -= 2;
    }

    while ( n > 0 ){
      ++ans;
      n -= k;
      k--;
    }
    out.print(ans);
  }
}
// Problem: 287_B. Pipeline
// Time complexity: logn
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.StringTokenizer;

/**
 * Created with IntelliJ IDEA.
 * User: ira
 * Date: 3/23/13
 * Time: 12:19 PM
 */
public class B2 {

        public static void main(String[] args) throws IOException {
            BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
            String line = reader.readLine();
            StringTokenizer tokenizer = new StringTokenizer(line);
            long n = Long.parseLong(tokenizer.nextToken());
            long k = Long.parseLong(tokenizer.nextToken());
            if (n == 1){
                System.out.println("0");
                return;
            }

            if (n <= k){
                System.out.println("1");
                return;
            }
            long first = 0;
            long end  = k;
            long mid;

            while (first < end){
                mid = first + (end - first)/2;
                if (is_exist(n, k , mid - 1)){
                    end = mid;
                } else {
                    first = mid + 1;
                }
            }
            if (is_exist(n, k, end - 1)){
                System.out.println((end ));
                return;
            }
            System.out.println("-1");
            return;

        }

    static boolean is_exist(long n, long k, long x){
        long res = n - (k - 1 + k - x)* (k - 1 - (k - x) + 1)/2;
        if (res <= k - x ){
            return true;
        }
        return false;
    }


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


public class CodeforcesRound176B {

	/**
	 * @param args
	 */
	public static void main(String[] args) 
	{
		Scanner  kde =new Scanner (System.in);
		Long n = kde.nextLong(); //дома  и кол труб 
		Long k = kde.nextLong();  // разветлители 
		if(((k-1)*(k-2)+2*k)<(n*(long)2))
		{
			System.out.println(-1);
			return;
		}	
		Long a,b;
		 if(n==1)
		 {
			 System.out.println(0);
			 return;
		 }
		
		 if(k>=n)
		 {
			 System.out.println(1);
			 return;
		 }
		 else
		 {
			a=(long)2;
			b=k-1;  
		 }	 
		 boolean flag =false;
		while(true)
		{
			if(a>=b)
			{
				
				break;
				
			
			}
			 long	c =(a+b)/2;
			 if(2*(k-c+1)+(k-1+k-c+1)*(c-1)<(n*2)) 
			 {
				 a=c+1;
			 }
			 else
			 {
				 b=c;
			 }	
			 flag=true;
		}
		if(flag==true )
		{
			System .out.println(a);
		}
		else
		{
			System .out.println(a);	
		}	

		
		
	}

}