It's been long after the events of the previous problems, and Karen has now moved on from student life and is looking to relocate to a new neighborhood.  The neighborhood consists of n houses in a straight line, labelled 1 to n from left to right, all an equal distance apart.Everyone in this neighborhood loves peace and quiet. Because of this, whenever a new person moves into the neighborhood, he or she always chooses the house whose minimum distance to any occupied house is maximized. If there are multiple houses with the maximum possible minimum distance, he or she chooses the leftmost one.Note that the first person to arrive always moves into house 1.Karen is the k-th person to enter this neighborhood. If everyone, including herself, follows this rule, which house will she move into?

The first and only line of input contains two integers, n and k (1 ≤ k ≤ n ≤ 1018), describing the number of houses in the neighborhood, and that Karen was the k-th person to move in, respectively.

Output a single integer on a line by itself, the label of the house Karen will move into.

NoteIn the first test case, there are 6 houses in the neighborhood, and Karen is the fourth person to move in:  The first person moves into house 1.  The second person moves into house 6.  The third person moves into house 3.  The fourth person moves into house 2. In the second test case, there are 39 houses in the neighborhood, and Karen is the third person to move in:  The first person moves into house 1.  The second person moves into house 39.  The third person moves into house 20.

import java.util.*;

/**
 * Created by zhengyanglzy on 2017/6/24.
 */
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        while (sc.hasNext()) {
            long houseNum = sc.nextLong();
            long k = sc.nextLong();
            System.out.println(cal(houseNum, k));
        }
    }

    static long cal(long houseNum, long k) {
        if (k == 1) {
            return 1;

        } else if (k == 2) {
            return houseNum;
        }
        return 1 + findLabel(houseNum - 2, k - 2);
    }

    static long findLabel(long houseNum, long k) {
        // System.out.printf("%d %d\n", houseNum, k);
        long medium = (houseNum + 1) / 2;
        if (k == 1) {
            return medium;
        }
        k -= 1;
        Part leftPart = new Part(medium - 1);
        Part rightPart = new Part(houseNum - medium);
        long leftTotal = 0;
        long rightTotal = 0;
        while (true) {
            long left = leftPart.peek();
            long right = rightPart.peek();
            if (left == 0 && right == 0) {
                break;
            }
            if (k > left + right) {
                k -= left + right;
                leftTotal += left;
                rightTotal += right;
                leftPart.split();
                rightPart.split();
                continue;
            }
            leftPart.collapse();
            rightPart.collapse();
            TreeSet<Long> set = new TreeSet<Long>();
            set.addAll(leftPart.segs.keySet());
            set.addAll(rightPart.segs.keySet());
            for (long len : set.descendingSet()) {
                if (leftPart.segs.containsKey(len)) {
                    if (leftPart.segs.get(len) >= k) {
                        return findLabel(medium - 1, leftTotal + k);
                    } else {
                        k -= leftPart.segs.get(len);
                        leftTotal += leftPart.segs.get(len);
                    }
                }
                if (rightPart.segs.containsKey(len)) {
                    if (rightPart.segs.get(len) >= k) {
                        return medium + findLabel(houseNum - medium, rightTotal + k);
                    } else {
                        k -= rightPart.segs.get(len);
                        rightTotal += rightPart.segs.get(len);
                    }
                }
            }
        }
        // 只剩1和2
        if (medium - 1 - leftTotal >= k) {
            return findLabel(medium - 1, leftTotal + k);
        }
        return medium + findLabel(houseNum - medium, rightTotal + k - (medium - 1 - leftTotal));
    }

    static class Part {
        Map<Long, Long> segs;

        Part(long num) {
            segs = new HashMap<Long, Long>();
            segs.put(num, 1L);
        }

        void split() {
            Map<Long, Long> newMap = new HashMap<Long, Long>();
            for (Map.Entry<Long, Long> entry : segs.entrySet()) {
                if (entry.getKey() <= 2) {
                    update(newMap, entry.getKey(), entry.getValue());
                    continue;
                }
                long medium = (entry.getKey() + 1) / 2;
                update(newMap, medium - 1, entry.getValue());
                update(newMap, entry.getKey() - medium, entry.getValue());
            }
            segs = newMap;
        }

        long peek() {
            long ret = 0;
            for (Map.Entry<Long, Long> entry : segs.entrySet()) {
                if (entry.getKey() > 2) {
                    ret += entry.getValue();
                }
            }
            return ret;
        }

        void collapse() {
            Map<Long, Long> newMap = new HashMap<Long, Long>();
            for (Map.Entry<Long, Long> entry : segs.entrySet()) {
                update(newMap, (entry.getKey() + 1) / 2, entry.getValue());
            }
            segs = newMap;
        }

        static void update(Map<Long, Long> map, long key, long inc) {
            if (!map.containsKey(key)) {
                map.put(key, 0L);
            }
            map.put(key, map.get(key) + inc);
        }
    }

    static class Seg implements Comparable<Seg> {
        int start;
        int length;

        public Seg(int start, int length) {
            this.start = start;
            this.length = length;
        }

        public int compareTo(Seg o) {
            int diff = (length - 1) / 2 - (o.length -1) / 2;
            if (diff != 0) {
                return -diff;
            }
            return start - o.start;
        }
    }
}

import java.io.*;
import java.util.*;

public class E {

	TreeMap<Long, Long> getCount(long len) {
		TreeMap<Long, Long> ret = new TreeMap<>();
		ret.put(len, 1L);
		long prev = Long.MAX_VALUE;
		while (true) {
			Map.Entry<Long, Long> e = ret.lowerEntry(prev);
			long key = e.getKey();
			prev = key;
			long cnt = e.getValue();
			if (key <= 1) {
				break;
			}

			for (int z = 0; z < 2; z++) {
				long toKey = (key - z) / 2;
				if (toKey == 0) {
					break;
				}
				ret.merge(toKey, cnt, Long::sum);
			}
		}
		return ret;
	}

	long getDist(long len) {
		return (len - 1) / 2;
	}

	void submit() {
		long n = nextLong();
		long k = nextLong() - 1;
		if (k < 2) {
			out.println(k == 0 ? 1 : n);
			return;
		}

		k -= 2;

		TreeMap<Long, Long> lens = new TreeMap<>(Collections.reverseOrder());
		TreeMap<Long, Long> tmp = getCount(n - 2);
		for (Map.Entry<Long, Long> e : tmp.entrySet()) {
			long len = e.getKey();
			long cnt = e.getValue();
			lens.merge(getDist(len), cnt, Long::sum);
		}

		long whatDist = -1;
		for (Map.Entry<Long, Long> e : lens.entrySet()) {
			long dist = e.getKey();
			long cnt = e.getValue();
			if (k >= cnt) {
				k -= cnt;
			} else {
				whatDist = dist;
				break;
			}
		}

		if (whatDist == -1) {
			throw new AssertionError();
		}

		long l = 2;
		long r = n - 1;

		while (true) {
			long m = (l + r) >> 1;
			if (getDist(r - l + 1) == whatDist) {
				if (k == 0) {
					out.println(m);
					return;
				} else {
					k--;
				}
			}
			tmp = getCount(m - l);
			long leftDist = tmp.getOrDefault(2 * whatDist + 1, 0L)
					+ tmp.getOrDefault(2 * whatDist + 2, 0L);
			if (k >= leftDist) {
				k -= leftDist;
				l = m + 1;
			} else {
				r = m - 1;
			}
		}

	}

	void preCalc() {

	}

	void stress() {

	}

	void test() {

	}

	E() throws IOException {
		br = new BufferedReader(new InputStreamReader(System.in));
		out = new PrintWriter(System.out);
		preCalc();
		submit();
		// stress();
		// test();
		out.close();
	}

	static final Random rng = new Random();

	static int rand(int l, int r) {
		return l + rng.nextInt(r - l + 1);
	}

	public static void main(String[] args) throws IOException {
		new E();
	}

	BufferedReader br;
	PrintWriter out;
	StringTokenizer st;

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

	String nextString() {
		try {
			return br.readLine();
		} catch (IOException e) {
			throw new RuntimeException(e);
		}
	}

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

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

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

import java.util.Scanner;

/**
 * Created by zhengyanglzy on 2017/6/24.
 */
public class Main {
    private static final int MAXIMUM_IND = 65;
    private static final long[] POWER;
    private static final long[] POWER_SUM;

    static {
        POWER = new long[MAXIMUM_IND];
        POWER_SUM = new long[MAXIMUM_IND];
        POWER[0] = POWER_SUM[0] = 0;
        POWER[1] = POWER_SUM[1] = 1;
        for (int i = 2; i < MAXIMUM_IND; ++i) {
            POWER[i] = POWER[i - 1] * 2;
            POWER_SUM[i] = POWER_SUM[i - 1] + POWER[i];
        }
    }

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        while (sc.hasNext()) {
            long houseNum = sc.nextLong();
            long k = sc.nextLong();
            if (k == 1) {
                System.out.println(1);
                continue;
            } else if (k == 2) {
                System.out.println(houseNum);
                continue;
            }
            System.out.println(1 + findLabel(houseNum - 2, k - 2));
        }
    }

    static long findLabel(long houseNum, long k) {
        long medium = (houseNum + 1) / 2;
        if (k == 1) {
            return medium;
        }
        k -= 1;
        int ind;
        for (ind = 1; k > 2 * POWER_SUM[ind]; ++ind) {
            k -= 2 * POWER_SUM[ind];
        }
        if (k <= POWER[ind] && POWER_SUM[ind - 1] + k <= medium - 1) {
            // left
            return findLabel(medium - 1, POWER_SUM[ind - 1] + k);
        }
        // right
        if (POWER_SUM[ind - 1] + k > medium - 1) {
            return medium + findLabel(houseNum - medium, POWER_SUM[ind - 1]+ k - (medium - 1 - POWER_SUM[ind - 1]));
        }
        return medium + findLabel(houseNum - medium, POWER_SUM[ind - 1] + k - POWER[ind]);
    }
}

import java.util.Random;
import java.util.Scanner;

/**
 * Created by zhengyanglzy on 2017/6/24.
 */
public class Main {
    private static final int MAXIMUM_IND = 65;
    private static final long[] POWER;
    private static final long[] POWER_SUM;
    static Random random = new Random(System.currentTimeMillis());

    static {
        POWER = new long[MAXIMUM_IND];
        POWER_SUM = new long[MAXIMUM_IND];
        POWER[0] = POWER_SUM[0] = 0;
        POWER[1] = POWER_SUM[1] = 1;
        for (int i = 2; i < MAXIMUM_IND; ++i) {
            POWER[i] = POWER[i - 1] * 2;
            POWER_SUM[i] = POWER_SUM[i - 1] + POWER[i];
        }
    }

    public static void main(String[] args) {
        // test(5000);
        Scanner sc = new Scanner(System.in);
        while (sc.hasNext()) {
            long houseNum = sc.nextLong();
            long k = sc.nextLong();
            if (k == 1) {
                System.out.println(1);
                continue;
            } else if (k == 2) {
                System.out.println(houseNum);
                continue;
            }
            System.out.println(1 + findLabel(houseNum - 2, k - 2));
        }
    }

    public static void test(int casenum) {
        while (casenum -- > 0) {
            long n = random.nextLong();
            long k = random.nextLong();
            if (k > n) {
                long tmp = n;
                n = k;
                k = tmp;
            }
            try {
                findLabel(n, k);
            } catch (StackOverflowError e) {
                System.err.printf("%d %d", n, k);
                break;
            }
        }
        System.out.println("over");
    }

    static long findLabel(long houseNum, long k) {
        //System.out.printf("%d %d\n", houseNum, k);
        long medium = (houseNum + 1) / 2;
        if (k == 1) {
            return medium;
        }
        k -= 1;
        Part left = new Part(0, medium - 1);
        Part right = new Part(medium, houseNum - medium);
        boolean strict = left.houseNum % 2 == 0 && right.houseNum - left.houseNum == 1;
        if (left.houseNum <= 2) {
            if (strict && k == 1) {
                return right.start + findLabel(right.houseNum, k);
            }
            if (k - (strict ? 1 : 0) <= left.houseNum) {
                return k - (strict ? 1 : 0);
            }
            return right.start + findLabel(right.houseNum, k - left.houseNum);
        }
        if (strict) {
            Part tmp = left;
            left = right;
            right = tmp;
        }
        int ind;
        for (ind = 1; k > 2 * POWER_SUM[ind]; ++ind);
        k -= 2 * POWER_SUM[ind - 1];
        if (left.houseNum - POWER_SUM[ind - 1] <= 2 && k <= left.houseNum - POWER_SUM[ind - 1]) {
            // 此时不满足规律
            return left.start + findLabel(left.houseNum, POWER_SUM[ind - 1] + k);
        }
        // if (k <= 2 && k == left.houseNum - POWER_SUM[ind - 1])
        if (k <= POWER[ind] && POWER_SUM[ind - 1] + k <= left.houseNum) {
            // left
            return left.start + findLabel(left.houseNum, POWER_SUM[ind - 1] + k);
        }
        // right
        long newK = POWER_SUM[ind - 1] + k - POWER[ind];
        if (POWER_SUM[ind - 1] + k > left.houseNum) {
            // 左边剩余的房子不一定够POWER[ind]
            newK = POWER_SUM[ind - 1]+ k - (left.houseNum - POWER_SUM[ind - 1]);
        }
        return right.start + findLabel(right.houseNum, newK);
    }

    static class Part {
        long start;
        long houseNum;

        Part(long start, long houseNum) {
            this.start = start;
            this.houseNum = houseNum;
        }
    }
}

import java.util.*;

/**
 * Created by zhengyanglzy on 2017/6/24.
 */
public class Main {
    private static final int MAXIMUM_IND = 65;
    private static final long[] POWER;
    private static final long[] POWER_SUM;
    private static final Map<Long, Long> SPACE;
    static Random random = new Random(System.currentTimeMillis());

    static {
        POWER = new long[MAXIMUM_IND];
        POWER_SUM = new long[MAXIMUM_IND];
        POWER[0] = POWER_SUM[0] = 0;
        POWER[1] = POWER_SUM[1] = 1;
        for (int i = 2; i < MAXIMUM_IND; ++i) {
            POWER[i] = POWER[i - 1] * 2;
            POWER_SUM[i] = POWER_SUM[i - 1] + POWER[i];
        }
        SPACE = new HashMap<Long, Long>();
        SPACE.put(0L, 0L);
        SPACE.put(1L, 0L);
        SPACE.put(2L, 0L);
    }

    public static void main(String[] args) {
        // testSO(5000);
        // compare(51, 400);
        Scanner sc = new Scanner(System.in);
        while (sc.hasNext()) {
            long houseNum = sc.nextLong();
            long k = sc.nextLong();
            System.out.println(cal(houseNum, k));
        }
    }

    public static void compare(int start, int end) {
        for (int i = start; i <= end; ++i) {
            List<Integer> res = generate(i);
            assert res.size() == i;
            boolean isMatch = true;
            for (int j = 0; j < res.size(); ++j) {
                long got = cal(i + 2, j + 3);
                long expected = res.get(j) + 1;
                if (expected != got) {
                    isMatch = false;
                    System.err.printf("(%d, %d) expected %d, got %d\n", i + 2, j + 3, expected, got);
                }
            }
            if (!isMatch) {
                break;
            }
            System.out.printf("complete %d\n", i);
        }
        System.out.println("over");
    }

    public static void testSO(int casenum) {
        while (casenum -- > 0) {
            long n = random.nextLong();
            long k = random.nextLong();
            if (k > n) {
                long tmp = n;
                n = k;
                k = tmp;
            }
            try {
                findLabel(n, k);
            } catch (StackOverflowError e) {
                System.err.printf("%d %d", n, k);
                break;
            }
        }
        System.out.println("over");
    }

    public static List<Integer> generate(int houseNum) {
        TreeSet<Seg> segs = new TreeSet<Seg>();
        segs.add(new Seg(1, houseNum));
        List<Integer> ret = new ArrayList<Integer>();
        while (!segs.isEmpty()) {
            Seg seg = segs.first();
            segs.remove(seg);
            int pos = (seg.length + 1) / 2 + seg.start - 1;
            ret.add(pos);
            if (pos - seg.start > 0) {
                segs.add(new Seg(seg.start, pos - seg.start));
            }
            if (seg.length + seg.start - pos - 1> 0) {
                segs.add(new Seg(pos + 1, seg.length + seg.start - pos - 1));
            }
        }
        return ret;
    }

    static long cal(long houseNum, long k) {
        if (k == 1) {
            return 1;

        } else if (k == 2) {
            return 2;
        }
        return 1 + findLabel(houseNum - 2, k - 2);
    }

    static long findSpace(long num) {
        if (SPACE.containsKey(num)) {
            return SPACE.get(num);
        }
        long medium = (num + 1) / 2;
        long res = 1 + findSpace(medium - 1) + findSpace(num - medium);
        SPACE.put(num, res);
        return res;
    }

    static long findLabel(long houseNum, long k) {
        // System.out.printf("%d %d\n", houseNum, k);
        long medium = (houseNum + 1) / 2;
        if (k == 1) {
            return medium;
        }
        /*
        long totalSpace = findSpace(houseNum);
        if (totalSpace < k) {
            // 慢慢填
            if (totalSpace == 0) {
                return k;
            }
            k -= totalSpace;
            long left = medium - 1 - findSpace(medium - 1);
            if (k <= left) {
                return findLabel(medium - 1, k + findSpace(medium - 1));
            }
            return medium + findLabel(houseNum - medium, k - left + findSpace(houseNum - medium));
        }*/
        k -= 1;
        Part leftPart = new Part(medium - 1);
        Part rightPart = new Part(houseNum - medium);
        long leftTotal = 0;
        long rightTotal = 0;
        while (true) {
            long left = leftPart.peek();
            long right = rightPart.peek();
            if (left == 0 && right == 0) {
                break;
            }
            if (k > left + right) {
                k -= left + right;
                leftTotal += left;
                rightTotal += right;
                leftPart.split();
                rightPart.split();
                continue;
            }
            leftPart.collapse();
            rightPart.collapse();
            TreeSet<Long> set = new TreeSet<Long>();
            set.addAll(leftPart.segs.keySet());
            set.addAll(rightPart.segs.keySet());
            for (long len : set.descendingSet()) {
                if (leftPart.segs.containsKey(len)) {
                    if (leftPart.segs.get(len) >= k) {
                        return findLabel(medium - 1, leftTotal + k);
                    } else {
                        k -= leftPart.segs.get(len);
                        leftTotal += leftPart.segs.get(len);
                    }
                }
                if (rightPart.segs.containsKey(len)) {
                    if (rightPart.segs.get(len) >= k) {
                        return medium + findLabel(houseNum - medium, rightTotal + k);
                    } else {
                        k -= rightPart.segs.get(len);
                        rightTotal += rightPart.segs.get(len);
                    }
                }
            }
        }
        // 只剩1和2
        if (medium - 1 - leftTotal >= k) {
            return findLabel(medium - 1, leftTotal + k);
        }
        return medium + findLabel(houseNum - medium, rightTotal + k - (medium - 1 - leftTotal));
    }

    static class Part {
        Map<Long, Long> segs;

        Part(long num) {
            segs = new HashMap<Long, Long>();
            segs.put(num, 1L);
        }

        void split() {
            Map<Long, Long> newMap = new HashMap<Long, Long>();
            for (Map.Entry<Long, Long> entry : segs.entrySet()) {
                if (entry.getKey() <= 2) {
                    update(newMap, entry.getKey(), entry.getValue());
                    continue;
                }
                long medium = (entry.getKey() + 1) / 2;
                update(newMap, medium - 1, entry.getValue());
                update(newMap, entry.getKey() - medium, entry.getValue());
            }
            segs = newMap;
        }

        long peek() {
            long ret = 0;
            for (Map.Entry<Long, Long> entry : segs.entrySet()) {
                if (entry.getKey() > 2) {
                    ret += entry.getValue();
                }
            }
            return ret;
        }

        void collapse() {
            Map<Long, Long> newMap = new HashMap<Long, Long>();
            for (Map.Entry<Long, Long> entry : segs.entrySet()) {
                update(newMap, (entry.getKey() + 1) / 2, entry.getValue());
            }
            segs = newMap;
        }

        static void update(Map<Long, Long> map, long key, long inc) {
            if (!map.containsKey(key)) {
                map.put(key, 0L);
            }
            map.put(key, map.get(key) + inc);
        }
    }

    static class Seg implements Comparable<Seg> {
        int start;
        int length;

        public Seg(int start, int length) {
            this.start = start;
            this.length = length;
        }

        public int compareTo(Seg o) {
            int diff = (length - 1) / 2 - (o.length -1) / 2;
            if (diff != 0) {
                return -diff;
            }
            return start - o.start;
        }
    }
}