class Array
  include Comparable
end

n = gets.to_s.to_i

# puts dfs(0,n)


cnt = 0
cr = n.to_s.chars.map{|t|t.to_i}
sz = n.to_s.size
3.upto(sz) do |i|
  
  [3, 5, 7].repeated_permutation(i) do |a|
    
    if a.include?(3) && a.include?(5) && a.include?(7) && a <= cr
      cnt += 1
      # p a
    end
  end
end

puts cnt