/* ID:chenjiong PROG:runround LANG:C++ */ #include <stdio.h> #include <string.h> int val[9]; int cnt; int vis[10]; void write(unsigned int x) { if ( x / 10 > 0 ) write( x / 10 ); vis[x % 10]++; val[cnt++] = x % 10; } bool is_ok(unsigned int x) { memset(vis,0,sizeof(vis)); cnt = 0; write(x); if ( vis[0] ) return false; int i; for ( i = 0; i < cnt; i++) if ( vis[i] > 1 ) return false; memset(vis,0,sizeof(vis)); int p = 0; vis[val[0]] = 1; int used = 1; while ( vis[val[p]] < 2 ) { p = ( p + val[p] ) % cnt; used = vis[val[p]] == 0 ? used + 1 : used; vis[val[p]]++; } if ( p == 0 && used == cnt ) return true; return false; } int main() { freopen("runround.in","r",stdin); freopen("runround.out","w",stdout); unsigned int M; scanf("%u",&M); unsigned int s; for ( s = M + 1; s <= 987654321; s++) { if ( is_ok(s) ) { printf("%u\n",s); break; } } return 0; }