{"raw_statement":[{"iden":"problem statement","content":"Given are a string $X$ consisting of `0` through `9`, and an integer $M$.\nLet $d$ be the greatest digit in $X$.\nHow many different integers not greater than $M$ can be obtained by choosing an integer $n$ not less than $d+1$ and seeing $X$ as a base-$n$ number?"},{"iden":"constraints","content":"*   $X$ consists of `0` through `9`.\n*   The length of $X$ is between $1$ and $60$ (inclusive).\n*   $X$ does not begin with a `0`.\n*   $1 \\leq M \\leq 10^{18}$"},{"iden":"input","content":"Input is given from Standard Input in the following format:\n\n$X$\n$M$"},{"iden":"sample input 1","content":"22\n10"},{"iden":"sample output 1","content":"2\n\nThe greatest digit in $X$ is `2`.\n\n*   By seeing $X$ as a base-$3$ number, we get $8$.\n*   By seeing $X$ as a base-$4$ number, we get $10$.\n\nThese two values are the only ones that we can obtain and are not greater than $10$."},{"iden":"sample input 2","content":"999\n1500"},{"iden":"sample output 2","content":"3\n\nThe greatest digit in $X$ is `9`.\n\n*   By seeing $X$ as a base-$10$ number, we get $999$.\n*   By seeing $X$ as a base-$11$ number, we get $1197$.\n*   By seeing $X$ as a base-$12$ number, we get $1413$.\n\nThese three values are the only ones that we can obtain and are not greater than $1500$."},{"iden":"sample input 3","content":"100000000000000000000000000000000000000000000000000000000000\n1000000000000000000"},{"iden":"sample output 3","content":"1\n\nBy seeing $X$ as a base-$2$ number, we get $576460752303423488$, which is the only value that we can obtain and are not greater than $1000000000000000000$."}],"translated_statement":null,"sample_group":[],"show_order":["default"],"formal_statement":null,"simple_statement":null,"has_page_source":true}