Use memoization to avoid reading too much.