#!/usr/bin/python3

robots = []

# number of robots
n = int(input("N robots: "))
# life years of robots
y = int(input("Life years: "))

# add life years in the beginning of array
robots.append([3] + [1 for i in range(n)])

while y > 0:

    n = 0
    # number of robots
    for i in robots:
        n += len(i) - 1
    
    # n // 3 - number of new groups of robots of 3
    # n // 5 - number of new groups of robots of 5
    # group of 3 robots create 5 robots
    # group of 5 robots create 9 robots

    if n % 3 == 0:
        robots.append([3] + [1 for i in range((n // 3) * 5)])
    elif n % 5 == 0:
        robots.append([3] + [1 for i in range((n // 5) * 9)])
    else:
        robots.append([3] + [1 for i in range((n // 3) * 5)])

    for i in range(len(robots)):
        # substract 1 life year from all robots in group
        robots[i][0] -= 1

    # utitlize death robots (life years == 0)
    robots = list(filter(lambda x: x[0] > 0, robots))

    y -= 1

n = 0
for i in robots:
    n += len(i) - 1
print(f"Number of robots: {n}")