n = gets.to_i

def f(n, acc)
  [3, 5, 7].each do |i|
    j = acc*10 + i
    if j <= n
      yield j
      f(n, j) { |k| yield k }
    end
  end
end

count = 0
f(n, 0) { |i|
  if i.to_s.chars.uniq.size == 3
    count += 1
  end
}
puts count
