import java.io.*; import java.util.*; public class Solution { static long cal(long m, long n) { if (m == 1) return n-1; long mid = m % 2; return cal(m/2, n) + cal(m/2+mid, n) + 1; } public static void main(String[] args) { Scanner sc = new Scanner(System.in); long m, n; m = sc.nextLong(); n = sc.nextLong(); System.out.println(cal(m,n)); } }