function is_753(number){
  return (number==3 || number==5 || number==7)
}

function is_753_number(n){
  const splitted = n.toString().split('');
  const numbers = new Set(splitted);
  if(numbers.size!=3){return false;}

  return numbers.has('3') && numbers.has('5') && numbers.has('7')
}

function main(input){
  const N = parseInt(input.trim());

  var result=0;
  for(var i=357;i<N;i+=2){
    if(is_753_number(i)){result++;}
  }

  console.log(result);

}

main(require('fs').readFileSync('/dev/stdin','utf8'))