N,*as=$<.read.split.map(&:to_i)

count = 0
3.upto(9) do |i|
    %w(3 5 7).repeated_permutation(i) do |a|
        s = a.join
        next unless s.include?('3') && s.include?('5') && s.include?('7')
        next if N < s.to_i
        count += 1
    end
end

puts count 