#n, m = gets.chomp.split.map(&:to_i)
#ary = []; n.times { cakes << gets.chomp.split.map(&:to_i).to_a } 
#def cb(i);	i==1 ? 1 : -1;end
n = gets.chomp.to_i.to_s
ans = 0
ary = ['3','5','7']
for i1 in 0..2
	for i2 in 0..2
		for i3 in 0..2
			for i4 in 0..2
				for i5 in 0..2
					for i6 in 0..2
						for i7 in 0..2
							for i8 in 0..2
								for i9 in 0..2
									ans +=1 if "#{ary[i1]}#{ary[i2]}#{ary[i3]}#{ary[i4]}#{ary[i5]}#{ary[i6]}#{ary[i7]}#{ary[i8]}#{ary[i9]}".to_i < n
								end
							end
						end
					end
				end
			end
		end
	end
end
p ans
