import java.io.*; import java.util.*; public class Solution { public static long cut( long M, long N ){ long a,b; if( M > N ){ a = N; b = M; }else{ a = M; b = N; } if( a == 0L ) return 0L; if( a == 1L ) return b-1L; //make even square if( (a&1) == 0 ){ if( a == b ){ //solve square return 3L+4L*cut(a/2L,a/2L); } //separate whats extra return 1L+cut(a,a)+cut(b-a,a); }else{ //separate whats extra return 1L+cut(a-1L,b)+cut(1L,b); } } public static void main(String[] args) { Scanner in = new Scanner(System.in); long M = in.nextLong(); long N = in.nextLong(); System.out.println( cut(M,N) ); } }