N = gets.to_i

def count753(num, keta, three, five, seven)
  return 0 if N < num
  # puts "#{num} #{keta}"
  [3, 5, 7].inject(three && five && seven ? 1 : 0) do |c, n|
    c + count753(num + n * keta, keta * 10, three || n == 3, five || n == 5, seven || n == 7)
  end
end

puts count753(0, 1, false, false, false)
