<?php
//error_reporting(0);
$N = trim(fgets(STDIN));
//list($N,$K) = explode(" ",trim(fgets(STDIN)));
//$a = explode(" ",trim(fgets(STDIN)));
//$H = explode(" ",trim(fgets(STDIN)));

function combine() {
    $args = func_get_args();

    $a = array_shift($args);
    $b = array_shift($args);

    $result = array();
    foreach ($a as $val1) {
        foreach ($b as $val2) {
            $result[] = array_merge((array)$val1, (array)$val2);
        }
    }

    if (count($args) > 0) {
        foreach ($args as $arg) {
            $result = combine($result, $arg);
        }
    }

    return $result;
}
$p = [3,5,7];
$n=0;
switch(strlen($N)) {
case 9:
  $n+=ncnt(combine($p,$p,$p,$p,$p,$p,$p,$p,$p));
case 8:
  $n+=ncnt(combine($p,$p,$p,$p,$p,$p,$p,$p));
case 7:
  $n+=ncnt(combine($p,$p,$p,$p,$p,$p,$p));
case 6:
  $n+=ncnt(combine($p,$p,$p,$p,$p,$p));
case 5:
  $n+=ncnt(combine($p,$p,$p,$p,$p));
case 4:
  $n+=ncnt(combine($p,$p,$p,$p));
case 3:
  $n+=ncnt(combine($p,$p,$p));
}
printf("%d\n",$n);

function ncnt($a) {
  global $N;
  foreach($a as $v) {
    $s = implode("",$v);
    if ((strpos($s,"3")!==false)
    && (strpos($s,"5")!==false)
    && (strpos($s,"7")!==false)) {
      if ($s < $N) {
        $l[]=$s;
      }
    }
  }
  return count($l);
}
