def eval(x)
  v = 0
  has3 = has5 = has7 = false
  for i in 0...x.size
    t = x[i]
    if t == 3
      has3 = true
    elsif t == 5
      has5 = true
    elsif t == 7
      has7 = true
    end
    v += t * (10**i)
  end
  return ((v <= $n && has3 && has5 && has7) ? 1 : 0)
end

$n = gets.to_i
a = [0,3,5,7]
r = 0
for d0 in a
  next if d0 == 0
  for d1 in a
    next if d1 == 0
    for d2 in a
      next if d2 == 0
      for d3 in a
        if d3 == 0
          r += eval([d0,d1,d2])
        else
          for d4 in a
            if d4 == 0
              r += eval([d0,d1,d2,d3])
            else
              for d5 in a
                if d5 == 0
                  r += eval([d0,d1,d2,d3,d4])
                else
                  for d6 in a
                    if d6 == 0
                      r += eval([d0,d1,d2,d3,d4,d5])
                    else
                      for d7 in a
                        if d7 == 0
                          r += eval([d0,d1,d2,d3,d4,d5,d6])
                        else
                          for d8 in a
                            if d8 == 0
                              r += eval([d0,d1,d2,d3,d4,d5,d6,d7])
                            else
                              r += eval([d0,d1,d2,d3,d4,d5,d6,d7,d8])
                            end
                          end
                        end
                      end
                    end
                  end
                end
              end
            end
          end
        end
      end
    end
  end
end
print r
