S = ["3", "5", "7"]

def ans(n, s)
  ret = (s.include?("3") && s.include?("5") && s.include?("7")) ? 1 : 0

  S.each do |e|
    nx = e + s
    if nx.to_i <= n
      ret += ans(n, nx)
    end
  end

  ret
end

n = gets.chomp.to_i

puts ans(n, "")
