ans = 0
n = gets.to_i
(1..9).each do |m|
  [?3,?5,?7].repeated_permutation(m).each do |a|
    s = a*''
    next unless s =~ /3/
    next unless s =~ /5/
    next unless s =~ /7/
    next if s.to_i > n
    ans += 1
  end
end
p ans