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[122221]; for(int i=0;i<10;i++){ kaibun[i] = i; kaibun[9+i] = 10*i+i; } //20 for(int i=0; i<10; i++){ for(int j=0;j<10;j++){ kaibun[20 + 10*i+j] = 101*i+10*j; kaibun[120 + 10*i+j] = 1001*i+110*j; } }//220 for(int i=0; i<10; i++){ for(int j=0;j<10;j++){ for(int k=0; k<10;k++){ kaibun[220 + 100*i+10*j+k] = 10001*i+1010*j+100*k ; kaibun[1220 + 100*i+10*j+k] = 100001*i+10010*j+1100*k; } } }//2220 for(int i=0; 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[2220 + 1000*i+100*j+10*k+l] = 1000001*i+100010*j+10100*k+1000*l ; kaibun[12220 +1000*i+100*j+10*k+l] = 10000001*i+1000010*j+100100*k+11000*l ; } } } }//22220 for(int i=0; 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[22220 + 10000*i+1000*j+100*k+10*l+m] = 10000001*i+1000010*j+100100*k+101000*l+10000*m ; } } } } }//122220 Arrays.sort(kaibun); ans = Arrays.binarySearch(kaibun, big); if (ans<0){ans = -ans -1;} if (Math.abs(Arrays.binarySearch(kaibun, small)) < ans) ans--; System.out.println(ans); } }