using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;

namespace algorithm
{
	class Program
	{

		public static void Main()
		{
			int n = int.Parse(Console.ReadLine());
			Queue<string> num = new Queue<string>();
			List<long> List = new List<long>();
			while (num.Count > 0)
			{
			}

			num.Enqueue("3");
			num.Enqueue("5");
			num.Enqueue("7");
			while (num.Count >0)
			{
				string tmp = num.Dequeue();
				if(tmp.Contains("3"))
					if (tmp.Contains("5"))
						if (tmp.Contains("7"))
							List.Add(long.Parse(tmp));
				if (tmp.Length < 11)
				{
					num.Enqueue(tmp + "3");
					num.Enqueue(tmp + "5");
					num.Enqueue(tmp + "7");
				}
			}

			Console.WriteLine(List.Count(x=>x<n && x >=357));
		}
		
	}

}


