import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.PrintStream;
import java.util.StringTokenizer;
import java.util.Scanner;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author Wolfgang Beyer
 */
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);
        TaskD solver = new TaskD();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskD {
        int found = 0;
        int queryCount = 0;
        int[] result = new int[8];

        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.nextInt();
            //int n = 100;
            //int n = 65536;

            int left = 1;
            int right = n + 1;
            while (left + 1 < right) {
                int middle = (left + right) / 2;
                int res = query(middle, 1, n, n);
                if (res == 2) left = middle;
                else if (res == 1) {
                    //System.out.println("Searching single: ");
                    findSingle(middle, 1, n, n);
                    found++;
                    break;
                } else {
                    right = middle;
                }
            }

            int top = 1;
            int bottom = n + 1;
            while (top + 1 < bottom) {
                int middle = (top + bottom) / 2;
                int res = query(1, middle, n, n);
                if (res == 2) top = middle;
                else if (res == 1) {
                    if ((found == 0) || (!containsRect(1, middle, n, n, result[0], result[1], result[2], result[3]))) {
                        //System.out.println("Searching single: ");
                        findSingle(1, middle, n, n);
                        found++;
                    }
                    break;
                } else {
                    bottom = middle;
                }
            }

            if (found < 2) {
                //System.out.println("Dia 3: ");
                left = 0;
                right = n;
                while (left + 1 < right) {
                    int middle = (left + right) / 2;
                    int res = query(1, 1, middle, n);
                    if (res == 2) right = middle;
                    else if (res == 1) {
                        if ((found == 0) || (!containsRect(1, 1, middle, n, result[0], result[1], result[2], result[3]))) {
                            //System.out.println("Searching single: ");
                            findSingle(1, 1, middle, n);
                            found++;
                        }
                        break;
                    } else {
                        left = middle;
                    }
                }
            }

            if (found < 2) {
                //System.out.println("Dia 4:");
                top = 0;
                bottom = n;
                while (top + 1 < bottom) {
                    int middle = (top + bottom) / 2;
                    int res = query(1, 1, n, middle);
                    if (res == 2) bottom = middle;
                    else if (res == 1) {
                        if ((found == 0) || (!containsRect(1, 1, n, middle, result[0], result[1], result[2], result[3]))) {
                            //System.out.println("Searching single: ");
                            findSingle(1, 1, n, middle);
                            found++;
                        }
                        break;
                    } else {
                        top = middle;
                    }
                }
            }

            System.out.print("! ");
            for (int i = 0; i < 8; i++) System.out.print(result[i] + " ");
            //System.out.println("\n" + queryCount + " queries used");
        }

        public boolean containsRect(int x1, int y1, int x2, int y2, int x3, int y3, int x4, int y4) {
            if ((x1 <= x3) && (y1 <= y3) && (x2 >= x4) && (y2 >= y4)) return true;
            return false;
        }

        public void findSingle(int x1, int y1, int x2, int y2) {
            x1 = findTopX(x1, y1, x2, y2);
            y1 = findTopY(x1, y1, x2, y2);
            x2 = findBottomX(x1, y1, x2, y2);
            y2 = findBottomY(x1, y1, x2, y2);
            //System.out.println("x1: " + x1 + ", y1: " + y1 + ", x2: " + x2 + ", y2: " + y2);
            result[0 + 4 * found] = x1;
            result[1 + 4 * found] = y1;
            result[2 + 4 * found] = x2;
            result[3 + 4 * found] = y2;
        }

        public int findTopX(int x1, int y1, int x2, int y2) {
            int left = x1;
            int right = x2;
            while (left + 1 < right) {
                int mid = (left + right) / 2;
                if (query(mid, y1, x2, y2) == 1) {
                    left = mid;
                } else {
                    right = mid;
                }
            }
            while (query(right, y1, x2, y2) == 0) right--;
            return right;
        }

        public int findTopY(int x1, int y1, int x2, int y2) {
            int left = y1;
            int right = y2;
            while (left + 1 < right) {
                int mid = (left + right) / 2;
                if (query(x1, mid, x2, y2) == 1) {
                    left = mid;
                } else {
                    right = mid;
                }
            }
            while (query(x1, right, x2, y2) == 0) right--;
            return right;
        }

        public int findBottomX(int x1, int y1, int x2, int y2) {
            int left = x1;
            int right = x2;
            while (left + 1 < right) {
                int mid = (left + right) / 2;
                if (query(x1, y1, mid, y2) == 1) {
                    right = mid;
                } else {
                    left = mid;
                }
            }
            while (query(x1, y1, left, y2) == 0) left++;
            return left;
        }

        public int findBottomY(int x1, int y1, int x2, int y2) {
            int left = y1;
            int right = y2;
            while (left + 1 < right) {
                int mid = (left + right) / 2;
                if (query(x1, y1, x2, mid) == 1) {
                    right = mid;
                } else {
                    left = mid;
                }
            }
            while (query(x1, y1, x2, left) == 0) left++;
            return left;
        }

        public int query(int x1, int y1, int x2, int y2) {
            queryCount++;

            System.out.println("? " + x1 + " " + y1 + " " + x2 + " " + y2);
            System.out.flush();
            Scanner sc = new Scanner(System.in);
            return sc.nextInt();

        /*int ret = 0;
        //if(x1 <= 17 && 57 <= x2 && y1 <= 80 && 80 <= y2) ++ret;
	    //if(x1 <= 25 && 88 <= x2 && y1 <= 51 && 61 <= y2) ++ret;
        if(x1 <= 10 && 10 <= x2 && y1 <= 11 && 11 <= y2) ++ret;
        //if(x1 <= 11 && 11 <= x2 && y1 <= 10 && 10 <= y2) ++ret;
        if(x1 <= 10 && 10 <= x2 && y1 <= 15 && 15 <= y2) ++ret;
        //System.out.println(x1 + ", " + y1 + ", " + x2 + ", " + y2 + ": " + ret);
	    return ret;*/
        }

    }

    static class InputReader {
        private static BufferedReader in;
        private static StringTokenizer tok;

        public InputReader(InputStream in) {
            this.in = new BufferedReader(new InputStreamReader(in));
        }

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

        public String next() {
            try {
                while (tok == null || !tok.hasMoreTokens()) {
                    tok = new StringTokenizer(in.readLine());
                }
            } catch (IOException ex) {
                System.err.println("An IOException was caught :" + ex.getMessage());
            }
            return tok.nextToken();
        }

    }
}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
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;
		FastScanner in = new FastScanner(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		TaskB solver = new TaskB();
		solver.solve(1, in, out);
		out.close();
	}

	static class TaskB {
		int n;
		int sepX;
		int sepY;
		int x1;
		int y1;
		int x2;
		int y2;
		FastScanner in;
		PrintWriter out;

		public void solve(int testNumber, FastScanner in, PrintWriter out) {
			this.in = in;
			this.out = out;
			n = in.nextInt();

			int x11, x12, y11, y12;
			int x21, x22, y21, y22;
			findSeparatingX();
			findSeparatingY();

			if (sepX >= 0) {
				locate(0, 0, sepX, n);
				x11 = x1;
				y11 = y1;
				x12 = x2;
				y12 = y2;
				locate(sepX, 0, n, n);
				x21 = x1;
				y21 = y1;
				x22 = x2;
				y22 = y2;
			} else {
				locate(0, 0, n, sepY);
				x11 = x1;
				y11 = y1;
				x12 = x2;
				y12 = y2;
				locate(0, sepY, n, n);
				x21 = x1;
				y21 = y1;
				x22 = x2;
				y22 = y2;
			}

			++x11;
			++x21;
			++y11;
			++y21;
			out.println("! " + x11 + " " + y11 + " " + x12 + " " + y12 + " " + +x21 + " " + y21 + " " + x22 + " " + y22);
			out.flush();
		}

		void locate(int x1, int y1, int x2, int y2) {
			for (int step = 15; step >= 0; step--) {
				int h = 1 << step;
				if (query(x1 + h, y1, x2, y2) > 0) {
					x1 += h;
				}
				if (query(x1, y1, x2 - h, y2) > 0) {
					x2 -= h;
				}
				if (query(x1, y1 + h, x2, y2) > 0) {
					y1 += h;
				}
				if (query(x1, y1, x2, y2 - h) > 0) {
					y2 -= h;
				}
			}
			this.x1 = x1;
			this.y1 = y1;
			this.x2 = x2;
			this.y2 = y2;
		}

		private void findSeparatingX() {
			int l = 0;
			int r = n;
			while (r - l > 1) {
				int m = (l + r) / 2;
				if (query(0, 0, m, n) == 0) {
					l = m;
				} else {
					r = m;
				}
			}
			sepX = -1;
			if (query(0, 0, r, n) == 1 && query(r, 0, n, n) == 1) {
				sepX = r;
			}
		}

		private void findSeparatingY() {
			int l = 0;
			int r = n;
			while (r - l > 1) {
				int m = (l + r) / 2;
				if (query(0, 0, n, m) == 0) {
					l = m;
				} else {
					r = m;
				}
			}
			sepY = -1;
			if (query(0, 0, n, r) == 1 && query(0, r, n, n) == 1) {
				sepY = r;
			}
		}

		int query(int x1, int y1, int x2, int y2) {
			if (x1 >= x2 || y1 >= y2) {
				return 0;
			}
			++x1;
			++y1;
			out.println("? " + x1 + " " + y1 + " " + x2 + " " + y2);
			out.flush();
			return in.nextInt();
		}

	}

	static class FastScanner {
		private BufferedReader in;
		private StringTokenizer st;

		public FastScanner(InputStream stream) {
			in = new BufferedReader(new InputStreamReader(stream));
		}

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

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

	}
}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author Hieu Le
 */
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();
    }

    static class TaskB {
        private int n;
        private InputReader in;
        private PrintWriter out;

        public void solve(int testNumber, InputReader in, PrintWriter out) {
            n = in.nextInt();
            this.in = in;
            this.out = out;
            query(new Point(1, 1), new Point(n, n), new Rectangle());
        }

        private boolean query(Point bottomLeft, Point topRight, Rectangle rectangle) {
            if (bottomLeft.r > topRight.r || bottomLeft.c > topRight.c)
                return false;

            // Find the column of the right edge.
            int low = bottomLeft.c, high = topRight.c;
            while (low < high) {
                int mid = low + (high - low) / 2;
                int answer = ask(bottomLeft.r, bottomLeft.c, topRight.r, mid);
                if (answer > 0)
                    high = mid;
                else
                    low = mid + 1;
            }
            int rightCol = low;

            // Find the column of the left edge.
            low = bottomLeft.c;
            high = topRight.c;
            while (low < high) {
                int mid = low + (high - low + 1) / 2;
                int answer = ask(bottomLeft.r, mid, topRight.r, topRight.c);
                if (answer > 0)
                    low = mid;
                else
                    high = mid - 1;
            }
            int leftCol = low;

            // Find the topmost row.
            low = bottomLeft.r;
            high = topRight.r;
            while (low < high) {
                int mid = low + (high - low) / 2;
                int answer = ask(bottomLeft.r, bottomLeft.c, mid, topRight.c);
                if (answer > 0)
                    high = mid;
                else
                    low = mid + 1;
            }
            int topRow = low;

            // Find the bottommost row.
            low = bottomLeft.r;
            high = topRight.r;
            while (low < high) {
                int mid = low + (high - low + 1) / 2;
                int answer = ask(mid, bottomLeft.c, topRight.r, topRight.c);
                if (answer > 0)
                    low = mid;
                else
                    high = mid - 1;
            }
            int bottomRow = low;

            if (leftCol > rightCol) {
                Rectangle first = new Rectangle();
                query(new Point(1, leftCol), new Point(n, n), first);
                Rectangle second = new Rectangle();
                query(new Point(1, 1), new Point(n, rightCol), second);
                out.printf("! %d %d %d %d %d %d %d %d\n",
                        first.bottomLeft.r, first.bottomLeft.c, first.topRight.r, first.topRight.c,
                        second.bottomLeft.r, second.bottomLeft.c, second.topRight.r, second.topRight.c);
                return true;
            }

            if (bottomRow > topRow) {
                Rectangle first = new Rectangle();
                query(new Point(bottomRow, 1), new Point(n, n), first);
                Rectangle second = new Rectangle();
                query(new Point(1, 1), new Point(topRow, n), second);
                out.printf("! %d %d %d %d %d %d %d %d\n",
                        first.bottomLeft.r, first.bottomLeft.c, first.topRight.r, first.topRight.c,
                        second.bottomLeft.r, second.bottomLeft.c, second.topRight.r, second.topRight.c);
                return true;
            }

            rectangle.bottomLeft.r = bottomRow;
            rectangle.bottomLeft.c = leftCol;
            rectangle.topRight.r = topRow;
            rectangle.topRight.c = rightCol;
            return true;
        }

        private int ask(int r1, int c1, int r2, int c2) {
            out.printf("? %d %d %d %d\n", r1, c1, r2, c2);
            out.flush();
            return in.nextInt();
        }

        private class Point {
            private int r;
            private int c;

            public Point(int r, int c) {
                this.r = r;
                this.c = c;
            }

        }

        private class Rectangle {
            private Point bottomLeft;
            private Point topRight;

            public Rectangle() {
                bottomLeft = new Point(-1, -1);
                topRight = new Point(-1, -1);
            }

        }

    }

    static class InputReader {
        private BufferedReader reader;
        private StringTokenizer tokenizer;
        private static final int BUFFER_SIZE = 32768;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), BUFFER_SIZE);
            tokenizer = null;
        }

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

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

    }
}


import java.io.*;
import java.util.*;
import java.math.*;
public class Main {
    InputStream is;
    PrintWriter out;
    String INPUT = "" ;
    boolean local = false;
    int inf=0x7FFFFFFF;
    int MOD=(int)(1e9+7);
    double eps=1e-5;
    double PI=Math.acos(-1);
    void solve() {
        long maxn=nl();
        long L=1,R=maxn,ans=-1;
        while (L<=R){
            long mid=(L+R)/2;
            if(ask(1,1,mid,maxn)<1)L=mid+1;
            else{
                R=mid-1;
                ans=mid;
            }
        }
        if(ask(1,1,ans,maxn)==1 && ask(ans+1,1,maxn,maxn)==1){
            Yts1999 a1=gao(1,1,ans,maxn);
            Yts1999 a2=gao(ans+1,1,maxn,maxn);
            answer(a1,a2);
        }else{
            L=1;R=maxn;ans=-1;
            while (L<=R){
                long mid=(L+R)/2;
                if(ask(1,1,maxn,mid)<1)L=mid+1;
                else{
                    R=mid-1;
                    ans=mid;
                }
            }
            Yts1999 a1=gao(1,1,maxn,ans);
            Yts1999 a2=gao(1,ans+1,maxn,maxn);
            answer(a1,a2);
        }
    }
    void answer(Yts1999 a1,Yts1999 a2){
        out.print("!");
        a1.print();
        a2.print();
        out.flush();
    }
    int ask(long a,long b,long c,long d){
        out.printf("? %d %d %d %d",a,b,c,d);
        out.println();
        out.flush();
        return ni();
    }
    Yts1999 gao(long x1,long x2,long y1,long y2){
        long a1=0,a2=0,a3=0,a4=0;
        long L,R;
        L=x1;R=y1;
        while(L<=R){
            long mid=(L+R)/2;
            if(ask(mid,x2,y1,y2)==1){
                a1=mid;
                L=mid+1;
            }else R=mid-1;
        }
        L=x1;R=y1;
        while(L<=R){
            long mid=(L+R)/2;
            if(ask(x1,x2,mid,y2)==1){
                a3=mid;
                R=mid-1;
            }else L=mid+1;
        }
        L=x2;R=y2;
        while(L<=R){
            long mid=(L+R)/2;
            if(ask(x1,mid,y1,y2)==1){
                a2=mid;
                L=mid+1;
            }else R=mid-1;
        }
        L=x2;R=y2;
        while(L<=R){
            long mid=(L+R)/2;
            if(ask(x1,x2,y1,mid)==1){
                a4=mid;
                R=mid-1;
            }else L=mid+1;
        }
        return new Yts1999(a1,a2,a3,a4);
    }
    public class Yts1999 implements Comparable{
        public long a,b,c,d;
        public Yts1999(long a,long b,long c,long d){
            this.a=a;
            this.b=b;
            this.c=c;
            this.d=d;
        }
        public int compareTo(Object o) {
            Yts1999 to=(Yts1999)o;
            if(this.d<to.d) return 1;
            else if(this.d==to.d) return 0;
            else return -1;
        }
        public void print(){
            out.printf(" %d %d %d %d",a,b,c,d);
        }
    }
    long[] exgcd(long a, long b) {
        if (b == 0) return new long[]{1,0,a};
        long[] res = exgcd(b, a%b);
        long t = res[0]; res[0] = res[1]; res[1] = t;
        res[1] -= a/b*res[0];
        return res;
    }
    long gcd(long a,long b){
        return b==0?a:gcd(b,a%b);
    }
    long lcm(long a,long b){
        return a*b/gcd(a,b);
    }
    private void run() {
        is = local? new ByteArrayInputStream(INPUT.getBytes()):System.in;
        out = new PrintWriter(System.out);
        long s = System.currentTimeMillis();
        solve();
        out.flush();
        tr(System.currentTimeMillis()-s+"ms");
    }
    public static void main(String[] args) throws Exception { new Main().run(); }
    private byte[] inbuf = new byte[1024];
    public int lenbuf = 0, ptrbuf = 0;
    private int readByte(){
        if(lenbuf == -1)throw new InputMismatchException();
        if(ptrbuf >= lenbuf){
            ptrbuf = 0;
            try { lenbuf = is.read(inbuf); } catch (IOException e) { throw new InputMismatchException(); }
            if(lenbuf <= 0)return -1;
        }
        return inbuf[ptrbuf++];
    }
    private boolean isSpaceChar(int c) { return !(c >= 33 && c <= 126); }
    private int skip() { int b; while((b = readByte()) != -1 && isSpaceChar(b)); return b; }
    private double nd() { return Double.parseDouble(ns()); }
    private char nc() { return (char)skip(); }
    private String ns(){
        int b = skip();
        StringBuilder sb = new StringBuilder();
        while(!(isSpaceChar(b))){ // when nextLine, (isSpaceChar(b) && b != ' ')
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }
    private char[] ns(int n){
        char[] buf = new char[n];
        int b = skip(), p = 0;
        while(p < n && !(isSpaceChar(b))){
            buf[p++] = (char)b;
            b = readByte();
        }
        return n == p ? buf : Arrays.copyOf(buf, p);
    }
    private char[][] nm(int n, int m){
        char[][] map = new char[n][];
        for(int i = 0;i < n;i++)map[i] = ns(m);
        return map;
    }
    private int[] na(int n){
        int[] a = new int[n];
        for(int i = 0;i < n;i++)a[i] = ni();
        return a;
    }
    private int ni(){
        int num = 0, b;
        boolean minus = false;
        while((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));
        if(b == '-'){
            minus = true;
            b = readByte();
        }
        while(true){
            if(b >= '0' && b <= '9'){
                num = num * 10 + (b - '0');
            }else{
                return minus ? -num : num;
            }
            b = readByte();
        }
    }
    private long nl(){
        long num = 0;
        int b;
        boolean minus = false;
        while((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));
        if(b == '-'){
            minus = true;
            b = readByte();
        }
        while(true){
            if(b >= '0' && b <= '9'){
                num = num * 10 + (b - '0');
            }else{
                return minus ? -num : num;
            }
            b = readByte();
        }
    }
    private void tr(Object... o) { if(local)System.out.println(Arrays.deepToString(o)); }
}


import java.io.*;
import java.math.*;
import static java.lang.Math.*;
import java.security.SecureRandom;
import static java.util.Arrays.*;
import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import sun.misc.Regexp;
import java.awt.geom.*;
import sun.net.www.content.text.plain;

public class Main {

    public static void main(String[] args) throws IOException {
        new Main().run();
    }
    StreamTokenizer in;
    PrintWriter out;
//deb////////////////////////////////////////////////

    public static void deb(String n, Object n1) {
        System.out.println(n + " is : " + n1);
    }

    public static void deb(int[] A) {

        for (Object oo : A) {
            System.out.print(oo + " ");
        }
        System.out.println("");
    }

    public static void deb(boolean[] A) {

        for (Object oo : A) {
            System.out.print(oo + " ");
        }
        System.out.println("");
    }

    public static void deb(double[] A) {

        for (Object oo : A) {
            System.out.print(oo + " ");
        }
        System.out.println("");
    }

    public static void deb(String[] A) {

        for (Object oo : A) {
            System.out.print(oo + " ");
        }
        System.out.println("");
    }

    public static void deb(int[][] A) {
        for (int i = 0; i < A.length; i++) {
            for (Object oo : A[i]) {
                System.out.print(oo + " ");
            }
            System.out.println("");
        }

    }

    public static void deb(double[][] A) {
        for (int i = 0; i < A.length; i++) {
            for (Object oo : A[i]) {
                System.out.print(oo + " ");
            }
            System.out.println("");
        }

    }

    public static void deb(long[][] A) {
        for (int i = 0; i < A.length; i++) {
            for (Object oo : A[i]) {
                System.out.print(oo + " ");
            }
            System.out.println("");
        }

    }

    public static void deb(String[][] A) {
        for (int i = 0; i < A.length; i++) {
            for (Object oo : A[i]) {
                System.out.print(oo + " ");
            }
            System.out.println("");
        }

    }
    /////////////////////////////////////////////////////////////

    int nextInt() throws IOException {
        in.nextToken();
        return (int) in.nval;
    }

    long nextLong() throws IOException {
        in.nextToken();
        return (long) in.nval;
    }

    void run() throws IOException {
//          in = new StreamTokenizer(new BufferedReader(new FileReader("input.txt")));
        // out = new PrintWriter(new FileWriter("output.txt"));
        in = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));
        out = new PrintWriter(new OutputStreamWriter(System.out));
        solve();
        out.flush();
    }
//boolean inR(int x,int y){
//return (x<=0)&&(x<4)&&(y<=0)&&(y<4);
//}
    @SuppressWarnings("unchecked")
    void solve() throws IOException {
        //   BufferedReader re= new BufferedReader(new FileReader("C:\\Users\\ASELA\\Desktop\\PROBLEMSET\\input\\F\\10.in"));
           BufferedReader re= new BufferedReader(new InputStreamReader(System.in));
     Scanner sc= new Scanner(System.in);
     long n=sc.nextLong(),k=sc.nextLong();
     if(k*(k-1)/2<n-1)
            System.out.println("-1");
     else{
     long ff=k*(k-1)/2;
     ff=-2*(n-1-ff);
     //    System.out.println(ff);
    long up=k,dw=0;
    while(up-dw>1){
    long c=(up+dw)/2;
    if(c*(c-1)<=ff)dw=c;
    else up=c;

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


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();
	}
}


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);
	}
}


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));
		}
	}
}


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();
	}
};


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);
  }
}


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();
	}
}


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;
    }
}


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);
	}
}


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);

    }
}


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();
	}
}


/**
 * 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);
    }
}


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;
    }

}


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);
	}
}


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);
		}
	}
}


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);

    }

}


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);
            }
        }
    }
}


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);
    }
}


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;
		}
	}
}


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;
    }

    }


/*
 * 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);
    }
}


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);
	}
}


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());
		}
	}
}


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);

	}
}


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());
	}
}


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());
    }

}


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));
		}
  }
}


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;
}


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();
	}
}


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;
	}
}


/*
 * 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;
    }

}


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;
}


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);
        }
    }


import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class Main {

   long k;

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

      if (n == 1) {
         prln(0);
         return;
      }

      if (n <= k) {
         prln(1);
         return;
      }

      long l = 1, r = k - 1;
      long mid = (l + r + 1) / 2;
      long old = -1;

      while (old != mid) {
         old = mid;

         if (take(mid) >= n)
            r = mid;
         if (take(mid) < n)
            l = mid;

         mid = (l + r + 1) / 2;
      }

      if (mid >= k || mid <= 0) {
         prln(-1);
         return;
      }

      if (take(mid) == n) {
         prln(mid);
         return;
      }

      if (mid == k - 1)
         prln(-1);
      else
         if (take(mid) < n)
            prln(mid + 1);
         else
            prln(mid);

   }

   long take(long t) {
      return k * t - t * (t - 1) / 2 - (t - 1);
   }

   public static void main(String[] args) {
      new Main().run();
   }

   public void run() {
      try {
         if (isFileIO) {
            pw = new PrintWriter(new File("output.out"));
            br = new BufferedReader(new FileReader("input.in"));
         } else {
            pw = new PrintWriter(System.out);
            br = new BufferedReader(new InputStreamReader(System.in));
         }
         solve();
         pw.close();
         br.close();
      } catch (IOException e) {
         System.err.println("IO Error");
      }
   }

   private int[] nia(int n) throws IOException {
      int arr[] = new int[n];
      for (int i = 0; i < n; ++i)
         arr[i] = Integer.parseInt(nextToken());
      return arr;
   }

   private int[] niam1(int n) throws IOException {
      int arr[] = new int[n];
      for (int i = 0; i < n; ++i)
         arr[i] = Integer.parseInt(nextToken()) - 1;
      return arr;
   }

   private long[] nla(int n) throws IOException {
      long arr[] = new long[n];
      for (int i = 0; i < n; ++i)
         arr[i] = Long.parseLong(nextToken());
      return arr;
   }

   private void pr(Object o) {
      pw.print(o);
   }

   private void prln(Object o) {
      pw.println(o);
   }

   private void prln() {
      pw.println();
   }

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

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

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

   private String nextToken() throws IOException {
      while (tokenizer == null || !tokenizer.hasMoreTokens()) {
         tokenizer = new StringTokenizer(br.readLine());
      }

      return tokenizer.nextToken();
   }

   // private void qsort(int a[]) {
   // Random rand = new Random(271828182l);
   // qsort(a, 0, a.length, rand);
   // }
   //
   // private void qsort(int a[], int l, int r, Random rand) {
   // if (r - l <= 1)
   // return;
   //
   // if (r - l == 2) {
   // if (a[r - 1] < a[l]) {
   // int t = a[r - 1];
   // a[r - 1] = a[l];
   // a[l] = t;
   // }
   //
   // return;
   // }
   //
   // int x = a[rand.nextInt(r - l) + l];
   // int i = l, j = r - 1;
   // while (i < j) {
   // while (a[i] < x)
   // ++i;
   // while (a[j] > x)
   // --j;
   // if (i < j) {
   // int t = a[i];
   // a[i] = a[j];
   // a[j] = t;
   // ++i;
   // --j;
   // }
   // }
   //
   // qsort(a, l, j + 1, rand);
   // qsort(a, i, r, rand);
   // }

   private BufferedReader br;
   private StringTokenizer tokenizer;
   private PrintWriter pw;
   private final boolean isFileIO = false;
}


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);
    }

}


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;
	   }
}


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 ( ); }
}


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);
    }
}


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;
    }
}


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);
        }
    }
}


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;
   }
}


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;
            }
        }
    }
}


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);
    }

}


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);
  }
}


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;
    }

}


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);
		}

	}

}


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;
		}
		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));
		}
  }
}


/**
 * 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;
        }

        /**
         * non-binary search version, O(n)
         * it will failed because of "over time limit erro" on this case:
         *  499999998500000001 1000000000   => 999955279
         *
         total = 1;
         for(int i = (int)k; i >= 2; i--) {
         total += i - 1;
         if(total >= n) {
         System.out.println(k-i+1);
         return;
         }
         }
         */

        /**
         * binary search search version. O(lgn)
         */
        int i = 2, j = (int) k;
        while (i < j) {
            int m = (i + j + 1) / 2;
            total = (k + m) * (k - m + 1) / 2 - (k - m);
            if (total < n)
                j = m - 1;
            else
                i = m;
        }
        System.out.println(k - i + 1);
    }
}


import java.io.IOException;
import java.util.Scanner;

public class TC
{
    static long N;
    static int k;
    static long WHOLESUM;

    static long SUM( long k )
    {
        long res=k*( k+1 )/2;
        return res-1;
    }

    static long returnPipes( int mid )
    {
        long not=SUM( mid-1 );
        long totpipes=WHOLESUM-not;
        int number=k-mid+1;
        long res=totpipes-number+1;
        return res;
    }

    static long binarySearch( int lo, int hi )
    {
        int res=Integer.MAX_VALUE;
        int val=0;
        while( lo <= hi )
        {
            int mid=( lo+hi )/2;
            long cnt=returnPipes( mid );
            val=k-mid+1;;

            if( cnt  < N )
            {
                hi=mid-1;
                continue;
            }
            else
            {
                res=Math.min( val, res );
                lo=mid+1;
            }
        }

        if( res==Integer.MAX_VALUE )
            return -1;
        else
            return res;

    }

    public static void main( String[] args ) throws IOException
    {
        Scanner s=new Scanner( System.in );
        N=s.nextLong();
        k=s.nextInt();
        WHOLESUM=SUM( k );
        if( N<=1 )
            System.out.println(0 );
        else
            System.out.println( binarySearch( 2, k ) );
    }

}


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 Dzmitry Paulenka
 */
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.nextLong();
        if (n == 1) {
            out.println(0);
            return;
        }
        if (k * (k - 1) < 2 * (n - 1)) {
            out.println(-1);
            return;
        }

        long sq2 = 4 * k * k - 4 * k + 1 - 4 * (2 * n - 2);
        long km = Math.max(2, (long) ((Math.sqrt(sq2) + 3) / 2.0) - 3);
        while (((km + k - 2)*(k - km + 1) >= 2*(n-1))) {
            ++km;
        }
        out.println(k - km + 2);
    }
}


import java.util.Locale;
import java.util.Scanner;

public class PipelineSolver {

    private long n;

    private long k;

    public static void main(String[] args) {
        PipelineSolver solver = new PipelineSolver();

        solver.readData();
        int solution = solver.solve();
        solver.print(solution);
    }

    private int gcd(int a, int b) {
        return b == 0 ? a : gcd(b, a % b);
    }

    private int lcm(int a, int b) {
        return a * b / gcd(a, b);
    }

    private void print(int[] values) {
        StringBuilder builder = new StringBuilder();

        for (int value : values) {
            builder.append(value);
            builder.append(" ");
        }

        print(builder);
    }

    private void print(Object value) {
        System.out.println(value);
    }

    private void print(boolean value) {
        System.out.println(value ? "YES" : "NO");
    }

    private void print(int value) {
        System.out.println(value);
    }

    private void print(long value) {
        System.out.println(value);
    }

    private void print(double value) {
        System.out.printf(Locale.ENGLISH, "%.10f", value);
    }

    private int[] getDigits(int number) {
        int[] digits = new int[10];
        int index = digits.length - 1;
        int digitsCount = 0;

        while (number > 0) {
            digits[index] = number % 10;
            number /= 10;
            index--;
            digitsCount++;
        }

        int[] result = new int[digitsCount];

        System.arraycopy(digits, digits.length - digitsCount, result, 0, digitsCount);

        return result;
    }

    private int[] readArray(Scanner scanner, int size) {
        int[] result = new int[size];

        for (int i = 0; i < size; i++) {
            result[i] = scanner.nextInt();
        }

        return result;
    }

    private void readData() {
        Scanner scanner = new Scanner(System.in);

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

    private int solve() {

        if (n == 1) {
            return 0;
        }
        if (n <= k) {
            return 1;
        }
        int result;
        long l;

        long d = (5 - 2 * k) * (5 - 2 * k) - 4 * (2 * n - 4 * k + 4);
        if (d < 0)
        {
            result = -1;
        } else {
            l = Math.min(Math.max((int)((2 * k - 3 - Math.sqrt(d)) / 2), 0), Math.max((int)((2 * k - 3 + Math.sqrt(d)) / 2), 0));

            long difference = n - k * (l + 1) + l * (l + 3) / 2;

            if (l > k - 2) {
                result = -1;
            } else if (l == k - 2) {
                result = difference == 0 ? (int) (l + 1) : -1;
            } else {
                result = (int) (l + 1 + (difference == 0 ? 0 : 1));
            }
        }

        return result;
    }
}