s = gets.chomp

def get_count keta, max
  ret = 0
  flg = max.to_s.length > keta ? false : true
  (3 ** keta).times do |i|
    tmp = i.to_s(3).rjust(keta, '0')
    if tmp.include?('0') && tmp.include?('1') && tmp.include?('2')
      if flg
        ret += 1 if tmp.gsub('0', '3').gsub('1', '5').gsub('2', '7').to_i <= max
      else
        ret += 1
      end
    end
  end
  ret
end

ret = 0
s.length.times do |i|
  ret += (get_count (i+1), s.to_i)
end
puts ret
