Write a positive integer in decimal without leading zeros. The number satisfies the rule when no digit appears three or more times. For example 20152015 satisfies the rule, and 1000 does not because the digit 0 appears three times.
Given a positive integer U, find the largest integer L with L≤U that satisfies the rule. Every one-digit number satisfies the rule, so such an L always exists.