while True: try: c, w = map(int, input().split()) except: break sum = 0 f = 0 while c >= 12 or w > 12: e = c // 12 c %= 12 if w - e >= 0: sum += e f += e w = w - e c += e else: sum += w w = 0 break c += f f = 0 while c < 12 and w > 1: w -= 1 c += 1 print(sum)