
//Stack Over Flow Recursive

using System;
using System.Collections;
using System.Collections.Generic;
namespace Ccs
{
    class Program
    {
        static void Main(string[] args)
        {
            var n = int.Parse(Console.ReadLine());

            var pr = new Program();

            var queue = new Queue<long>();
            queue.Enqueue(0);
            long x = 0;
            int count = 0;

            while (x <= n)
            {

                x = queue.Dequeue();
                if (pr.Is_sgs(x))
                {
                    count++;
                    Console.WriteLine(x);
                }

                for (int i = 3; i <= 7; i += 2)
                    queue.Enqueue(x * 10 + i);

//                if (queue.Count>0)
            }
            Console.WriteLine(count);

//          var pr = new Program();
//          Console.WriteLine(pr.Rec(0,n));
        }

        private const String sgs = "357";
        private bool Is_sgs(String s)
        {
           
            bool is_sgs_ = true;
            foreach(char c in sgs )
                is_sgs_ &= s.Contains(c);
           
            return is_sgs_;
        }   
        
        private bool Is_sgs(long n)
        {
            return this.Is_sgs(n.ToString());
        }


        private int Rec(int x, int n)
        {
            //            var x = int.Parse(s);
            if (n < x)
                return 0;
            //            if (Is_sgs(x))
            //                Console.WriteLine(x);

            var ret = Is_sgs(x) ? 1 : 0;

            foreach ( var c in sgs)
                ret += Rec(x * 10 + int.Parse( c.ToString() ), n);

            return ret;
        }

    }
}
