def ascan; gets.split.map(&:to_i); end

s = gets
l = s.size
N = s.to_i
ans = 0
3.upto(l) do |i|
    [7,5,3].repeated_permutation(i) do |e|
        next unless e.include?(7) && e.include?(5) && e.include?(3)
        ans += 1 if e.reduce(0){|s,e| s*10+e } <= N
    end
end

p ans