import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.Arrays; public class Main { public static void main(String[] args)throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); long n = Long.parseLong(br.readLine()); int big = (int) (n/1000000000); int small = (int) (n%1000000000); int ans = 0; int[] kaibun = new int[110001]; for(int i=1;i<10;i++){ kaibun[i] = i; kaibun[9+i] = 10*i+i; } //20 for(int i=1; i<10; i++){ for(int j=0;j<10;j++){ kaibun[9 + 10*i+j] = 101*i+10*j; kaibun[99 + 10*i+j] = 1001*i+110*j; } }//200 for(int i=1; i<10; i++){ for(int j=0;j<10;j++){ for(int k=0; k<10;k++){ kaibun[89 + 100*i+10*j+k] = 10001*i+1010*j+100*k ; kaibun[989 + 100*i+10*j+k] = 100001*i+10010*j+1100*k; } } }//2000 for(int i=1; i<10; i++){ for(int j=0;j<10;j++){ for(int k=0; k<10;k++){ for(int l=0;l<10;l++){ kaibun[889 + 1000*i+100*j+10*k+l] = 1000001*i+100010*j+10100*k+1000*l ; kaibun[9889 +1000*i+100*j+10*k+l] = 10000001*i+1000010*j+100100*k+11000*l ; } } } }//20000 for(int i=1; i<10; i++){ for(int j=0;j<10;j++){ for(int k=0; k<10;k++){ for(int l=0;l<10;l++){ for(int m=0; m<10; m++){ kaibun[8889 + 10000*i+1000*j+100*k+10*l+m] = 10000001*i+1000010*j+100100*k+101000*l+10000*m ; } } } } }//110000 ans = Arrays.binarySearch(kaibun, big); if (ans<0){ans = -ans -1;} if (Math.abs(Arrays.binarySearch(kaibun, small)) < ans) ans--; System.out.println(ans); } }