def solution(limit: int = 5000) -> int:
    pentagonal_nums = [(i * (3 * i - 1)) // 2 for i in range(1, limit)]
    for i, pentagonal_i in enumerate(pentagonal_nums):
        for j in range(i, len(pentagonal_nums)):
            pentagonal_j = pentagonal_nums[j]
            a = pentagonal_i + pentagonal_j
            b = pentagonal_j - pentagonal_i
            if is_pentagonal(a) and is_pentagonal(b):
                return b

    return -1