use v5.18;
use warnings;
use List::Util qw( all sum );
sub read_line { chomp(my $s = <>); $s }
sub splited_read_line { split / /, read_line }

my $n = read_line;

sub count {
  my ($s, $c) = @_;
  my @chars = split //, $s;
  my @counter = grep { $_ eq $c } @chars;
  scalar @counter;
}

sub dfs {
  my $s = shift;
  if ( int( $s eq '' ? 0 : $s ) > $n ) {
    0;
  }
  else {
    my $is_753 = ( all { count $s, $_ } split //, '753' ) ? 1 : 0;
    sum( ( map { dfs($s . $_) } split //, '753' ), $is_753 );
  }
}

say dfs('');
