<?php
$num = explode(' ', trim(fgets(STDIN)));
//var_dump($num[0]);
$nums=range(0, $num[0]);
//var_dump($nums);
$count=0;
foreach ($nums as $i) {
   if($i%2==0){continue;}; 
    $aryTmp = str_split($i);
//    echo $aryTmp;
    if (!in_array ( 0 , $aryTmp) and
        !in_array ( 1 ,  $aryTmp) and
        !in_array ( 2 ,  $aryTmp) and
        !in_array ( 4 ,  $aryTmp) and
        !in_array ( 6 ,  $aryTmp) and
        !in_array ( 8 ,  $aryTmp) and
        !in_array ( 9 ,  $aryTmp )and
        in_array ( 3 ,  $aryTmp )and in_array ( 5 ,  $aryTmp ) and in_array ( 7 ,  $aryTmp )){$count+=1;}


}
echo $count;

  
?>
  