N = gets.chomp
keta = N.length
count = 0
for i in (3..keta) do
    ary = [3, 5, 7].repeated_permutation(i).to_a
    ary.each do |a|
        if a.include?(3) && a.include?(5) && a.include?(7) && a.join.to_i <= N.to_i
            count += 1   
        end  
    end
end

puts count 