#!/usr/bin/env ruby
n = STDIN.readline.strip.to_i

def make_753()
  p = []
  for i in 1..9 do
    p += _make_753(i)
  end
  p
end

def _make_753(d)
  p = ['7', '5', '3']
  for i in 2..d
    p = p.product(['7', '5', '3']).map{|d| d.join}.flatten
  end
  p.select{|s| exist_753(s)}.map(&:to_i)
end

def exist_d(d, s)
  s.split('').include?(d.to_s)
end

def exist_753(s)
  exist_d(7, s) and exist_d(5, s) and exist_d(3, s)
end

_753 = make_753()
puts _753.count{|d| n >= d}