a, b = map(int, input().split()) n = -(-a // 3) n_min = n*3 if n_min < b: print() n_min +=3