cho.sh
Notes
Loading...

Square-Substring-Free Number

Time limit

1s

Memory limit

1024 MB

Problem

For an integer aaa, write a2a^2a2 in decimal notation. A positive integer NNN is called a square-substring-free number if none of those decimal strings appears as a substring of the decimal representation of NNN.

In increasing order, these numbers begin as 2,3,5,6,7,8,22,23,26,…2, 3, 5, 6, 7, 8, 22, 23, 26, \ldots2,3,5,6,7,8,22,23,26,….

Given a positive integer NNN, find the smallest square-substring-free number that is at least NNN.

Input

A positive integer NNN is given.

1≤N≤10181 \le N \le 10^{18}1≤N≤1018

Output

Print the smallest square-substring-free number that is at least NNN.