#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
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 && [ary[i1],ary[i2],ary[i3],ary[i4],ary[i5],ary[i6],ary[i7],ary[i8],ary[i9]].uniq.size ==3
										
								end
							end
						end
					end
				end
			end
		end
	end
end
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
								ans +=1 if "#{ary[i1]}#{ary[i2]}#{ary[i3]}#{ary[i4]}#{ary[i5]}#{ary[i6]}#{ary[i7]}#{ary[i8]}".to_i < n && [ary[i1],ary[i2],ary[i3],ary[i4],ary[i5],ary[i6],ary[i7],ary[i8]].uniq.size ==3
							end
						end
					end
				end
			end
		end
	end
end
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
							ans +=1 if "#{ary[i1]}#{ary[i2]}#{ary[i3]}#{ary[i4]}#{ary[i5]}#{ary[i6]}#{ary[i7]}".to_i < n && [ary[i1],ary[i2],ary[i3],ary[i4],ary[i5],ary[i6],ary[i7]].uniq.size ==3
						end
					end
				end
			end
		end
	end
end
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
						ans +=1 if "#{ary[i1]}#{ary[i2]}#{ary[i3]}#{ary[i4]}#{ary[i5]}#{ary[i6]}".to_i < n && [ary[i1],ary[i2],ary[i3],ary[i4],ary[i5],ary[i6]].uniq.size ==3
					end
				end
			end
		end
	end
end
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
					ans +=1 if "#{ary[i1]}#{ary[i2]}#{ary[i3]}#{ary[i4]}#{ary[i5]}".to_i < n && [ary[i1],ary[i2],ary[i3],ary[i4],ary[i5]].uniq.size ==3
				end
			end
		end
	end
end
for i1 in 0..2
	for i2 in 0..2
		for i3 in 0..2
			for i4 in 0..2
				ans +=1 if "#{ary[i1]}#{ary[i2]}#{ary[i3]}#{ary[i4]}".to_i < n &&[ary[i1],ary[i2],ary[i3],ary[i4]].uniq.size ==3
			end
		end
	end
end
for i1 in 0..2
	for i2 in 0..2
		for i3 in 0..2
			ans +=1 if "#{ary[i1]}#{ary[i2]}#{ary[i3]}".to_i < n && [ary[i1],ary[i2],ary[i3]].uniq.size ==3
		end
	end
end

puts ans
