N = gets.to_i

values = []
3.upto(9) do |digit|
  0.upto(3**digit-1) do |pattern|
    v = 0
    digit.times do
      m = pattern % 3
      if m == 0
        v = 10*v + 3
      elsif m == 1
        v = 10*v + 5
      elsif m == 2
        v = 10*v + 7
      end
      pattern /= 3
    end

    if v <= N && v.to_s.include?('3') && v.to_s.include?('5') && v.to_s.include?('7')
      values << v
    end
  end
end

p values.size
