using System;
using System.Linq;
using System.Collections.Generic;

namespace Contest
{
    class Program
    {
        static void Main(string[] args)
        {
            ABC114.C();
        }
        
        class ABC114
        {
            public static void A()
            {
                Console.WriteLine(new int[] { 7, 5, 3 }.Contains(Read.Int()) ? "YES" : "NO");
            }
            public static void B()
            {
                var S = Read.Str();
                int min = 9999;
                for (int i = 0; i < S.Length - 2; ++i)
                {
                    var v = Convert.ToInt32(S.Substring(i, 3));
                    min = Math.Min(min, Math.Abs(753 - v));
                }
                Console.WriteLine(min);
            }
            public static void C()
            {
                var N = Read.Int();
                List<long> list = new List<long>();
                C_Loop(N, 0, list);
                int count = 0;
                foreach (var v in list)
                {
                    var v2 = v;
                    var keta = new int[10];
                    while (v2 > 0)
                    {
                        keta[v2 % 10]++;
                        v2 /= 10;
                    }
                    if (keta[3] * keta[5] * keta[7] > 0) { count++; }
                }
                Console.WriteLine(count);
            }
            static void C_Loop(long N, long X, List<long> list)
            {
                long v;
                v = X * 10 + 3; if (N >= v) { list.Add(v); C_Loop(N, v, list); }
                v = X * 10 + 5; if (N >= v) { list.Add(v); C_Loop(N, v, list); }
                v = X * 10 + 7; if (N >= v) { list.Add(v); C_Loop(N, v, list); }
            }
            public static void D()
            {
                var N = Read.Int();
                var fact = new Dictionary<long, int>();
                for(int i = 1; i <= N; ++i)
                {
                    var f = Util.Factorize(i);
                    foreach(var kvp in f)
                    {
                        if (!fact.ContainsKey(kvp.Key)) { fact.Add(kvp.Key, 0); }
                        fact[kvp.Key] += kvp.Value;
                    }
                }
                var divs = fact.Values.ToArray();
                long count = 0;
                {
                    count += divs.Count(x => x >= 74);
                }
                {
                    var c25 = divs.Count(x => x >= 24);
                    var c3 = divs.Count(x => x >= 2);
                    count += c25 * (c25 - 1) + c25 * (c3 - c25);
                }
                {
                    var c15 = divs.Count(x => x >= 14);
                    var c5 = divs.Count(x => x >= 4);
                    count += c15 * (c15 - 1) + c15 * (c5 - c15);
                }
                {
                    var c5 = divs.Count(x => x >= 4);
                    var c3 = divs.Count(x => x >= 2);
                    count += c5 * (c5 - 1) * (c5 - 2) / 2 + (c5 * (c5 - 1) / 2 * (c3 - c5));
                }
                Console.WriteLine(count);
            }
        }

        class Util
        {
            public static Dictionary<long, int> Factorize(long x)
            {
                var dict = new Dictionary<long, int>();
                long minp = 2;
                while (x > 1)
                {
                    bool ok = false;
                    for (long p = minp; p * p <= x; ++p)
                    {
                        if (x % p == 0)
                        {
                            if (!dict.ContainsKey(p))
                            {
                                dict.Add(p, 0);
                            }
                            dict[p]++;
                            minp = p;
                            x /= p;
                            ok = true;
                            break;
                        }
                    }
                    if (!ok)
                    {
                        if (!dict.ContainsKey(x)) { dict.Add(x, 0); }
                        dict[x]++;
                        break;
                    }
                }
                return dict;
            }
        }

        static class Read
        {
            static Queue<string> queue = new Queue<string>();
            static void Enqueue() { var ss = Console.ReadLine().Split(' '); foreach (var s in ss) { queue.Enqueue(s); } }
            public static int Int() { if (queue.Count == 0) { Enqueue(); } return Convert.ToInt32(queue.Dequeue()); }
            public static long Long() { if (queue.Count == 0) { Enqueue(); } return Convert.ToInt64(queue.Dequeue()); }
            public static string Str() { if (queue.Count == 0) { Enqueue(); } return queue.Dequeue(); }
            public static int[] IntN() { return Console.ReadLine().Split(' ').Select(s => Convert.ToInt32(s)).ToArray(); }
            public static long[] LongN() { return Console.ReadLine().Split(' ').Select(s => Convert.ToInt64(s)).ToArray(); }
            public static string[] StrN() { return Console.ReadLine().Split(' '); }
            public static Tuple<int, int>[] TupleInt(int n) { List<Tuple<int, int>> list = new List<Tuple<int, int>>(); for (int i = 0; i < n; ++i) { var ab = Read.IntN(); list.Add(new Tuple<int, int>(ab[0], ab[1])); } return list.ToArray(); }
            public static Tuple<long, long>[] TupleLong(int n) { List<Tuple<long, long>> list = new List<Tuple<long, long>>(); for (int i = 0; i < n; ++i) { var ab = Read.LongN(); list.Add(new Tuple<long, long>(ab[0], ab[1])); } return list.ToArray(); }
            public static Tuple<string, string>[] TupleStr(int n) { List<Tuple<string, string>> list = new List<Tuple<string, string>>(); for (int i = 0; i < n; ++i) { var ab = Read.StrN(); list.Add(new Tuple<string, string>(ab[0], ab[1])); } return list.ToArray(); }
            public static Tuple<double, double>[] TupleDouble(int n) { List<Tuple<double, double>> list = new List<Tuple<double, double>>(); for (int i = 0; i < n; ++i) { var ab = Read.LongN(); list.Add(new Tuple<double, double>(ab[0], ab[1])); } return list.ToArray(); }
            public static long[,] LongMatrix(int r, int c)
            {
                var mat = new long[r, c];
                for (int i = 0; i < r; ++i)
                {
                    var x = Read.LongN();
                    for (int j = 0; j < c; ++j)
                    {
                        mat[i, j] = x[j];
                    }
                }
                return mat;
            }
            public static Dictionary<int, HashSet<int>> AdjacencyList(int N, int M)
            {
                Dictionary<int, HashSet<int>> dict = new Dictionary<int, HashSet<int>>();
                for (int i = 0; i <= N; ++i)
                {
                    dict.Add(i, new HashSet<int>());
                }
                for (int i = 0; i < M; ++i)
                {
                    var ab = Read.IntN();
                    dict[ab[0]].Add(ab[1]);
                    dict[ab[1]].Add(ab[0]);
                }
                return dict;
            }
        }
    }
}


Measured memory_bytes: 15712