import sys


def main():
    positions = tuple(int(line.split()[-1]) for line in sys.stdin)
    scores = 0, 0
    roll_count = 0

    while max(scores) < 1000:
        position, other_position = positions
        score, other_score = scores

        roll_count += 3
        roll = sum((roll_count - i - 1) % 100 + 1 for i in range(3))
        position = (position + roll - 1) % 10 + 1
        score += position

        positions = other_position, position
        scores = other_score, score

    print(min(scores) * roll_count)


if __name__ == "__main__":
    main()
