Robbers, who attacked the Gerda's cab, are very successful in covering from the kingdom police. To make the goal of catching them even harder, they use their own watches.First, as they know that kingdom police is bad at math, robbers use the positional numeral system with base 7. Second, they divide one day in n hours, and each hour in m minutes. Personal watches of each robber are divided in two parts: first of them has the smallest possible number of places that is necessary to display any integer from 0 to n - 1, while the second has the smallest possible number of places that is necessary to display any integer from 0 to m - 1. Finally, if some value of hours or minutes can be displayed using less number of places in base 7 than this watches have, the required number of zeroes is added at the beginning of notation.Note that to display number 0 section of the watches is required to have at least one place.Little robber wants to know the number of moments of time (particular values of hours and minutes), such that all digits displayed on the watches are distinct. Help her calculate this number.

The first line of the input contains two integers, given in the decimal notation, n and m (1 ≤ n, m ≤ 109) — the number of hours in one day and the number of minutes in one hour, respectively.

Print one integer in decimal notation — the number of different pairs of hour and minute, such that all digits displayed on the watches are distinct.

NoteIn the first sample, possible pairs are: (0: 1), (0: 2), (1: 0), (1: 2).In the second sample, possible pairs are: (02: 1), (03: 1), (04: 1), (05: 1), (06: 1).

using System;

namespace Problem_C
{
    class Main_CLass
    {
        static void Main(string[] args)
        {

            Console.WriteLine((new Solution()).Solve_Problem());
            Console.ReadLine();
        }
    }
    class Solution
    {
        string[] str;
        public long Solve_Problem()
        {
            str = Console.ReadLine().Split(' ');
            long n = long.Parse(str[0]); long m = long.Parse(str[1]);
            long left_dial = Seventh_Notanion(n - 1).Length; long right_dial = Seventh_Notanion(m - 1).Length;
            long dial = left_dial + right_dial;
            if (dial > 7) return 0;
            long ans = 0;
            for (long i = 0; i < n; i++)
                for (long j = 0; j < m; j++)
                {
                    string left_face = Seventh_Notanion(i);
                    while (left_face.Length != left_dial) left_face = '0' + left_face;
                    string right_face = Seventh_Notanion(j);
                    while (right_face.Length != right_dial) right_face = '0' + right_face;
                    string face = left_face + right_face;
                    if (IsCorrect(face))
                        ans++;
                }
            return ans;
        }
        public string Seventh_Notanion(long x)
        {
            string ans = "";
            while (x > 0)
            {
                ans = (x % 7).ToString() + ans;
                x /= 7;
            }
            if (ans == "") return "0";
            return ans;
        }
        public static bool IsCorrect(string s)
        {
            for (int i = 0; i < s.Length; i++)
                for (int j = i + 1; j < s.Length; j++)
                    if (s[i] == s[j]) return false;
            return true;
        }
    }
}

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

namespace TaskC
{
    class Program
    {
        static void Main(string[] args)
        {
            new Solver().Solve().OutputResult();
        }

        private class ExtendedReader : StreamReader
        {
            private static readonly char Separator = ' ';

            public ExtendedReader(Stream stream) : base(stream) { }
            public ExtendedReader(Stream stream, bool detectEncodingFromByteOrderMarks) : base(stream, detectEncodingFromByteOrderMarks) { }
            public ExtendedReader(Stream stream, Encoding encoding) : base(stream, encoding) { }
            public ExtendedReader(Stream stream, Encoding encoding, bool detectEncodingFromByteOrderMarks) : base(stream, encoding, detectEncodingFromByteOrderMarks) { }
            public ExtendedReader(Stream stream, Encoding encoding, bool detectEncodingFromByteOrderMarks, int bufferSize) : base(stream, encoding, detectEncodingFromByteOrderMarks, bufferSize) { }
            public ExtendedReader(Stream stream, Encoding encoding, bool detectEncodingFromByteOrderMarks, int bufferSize, bool leaveOpen) : base(stream, encoding, detectEncodingFromByteOrderMarks, bufferSize, leaveOpen) { }
            public ExtendedReader(string path) : base(path) { }
            public ExtendedReader(string path, bool detectEncodingFromByteOrderMarks) : base(path, detectEncodingFromByteOrderMarks) { }
            public ExtendedReader(string path, Encoding encoding) : base(path, encoding) { }
            public ExtendedReader(string path, Encoding encoding, bool detectEncodingFromByteOrderMarks) : base(path, encoding, detectEncodingFromByteOrderMarks) { }
            public ExtendedReader(string path, Encoding encoding, bool detectEncodingFromByteOrderMarks, int bufferSize) : base(path, encoding, detectEncodingFromByteOrderMarks, bufferSize) { }

            public char ReadChar()
            {
                return (char)this.Read();
            }

            public double ReadDoubleFromArray()
            {
                StringBuilder sb = new StringBuilder();
                char ch = this.ReadChar();
                while (ch != Separator && ch != '\n')
                {
                    sb.Append(ch);
                    ch = this.ReadChar();
                }
                return Convert.ToDouble(sb.ToString());
            }

            public int ReadInt()
            {
                return int.Parse(this.ReadLine());
            }

            public Int64 ReadInt64()
            {
                return Int64.Parse(this.ReadLine());
            }

            public int[] ReadIntArray()
            {
                return this.ReadLine().Split(' ').Select(int.Parse).ToArray();
            }

            public char[] ReadCharArray()
            {
                return this.ReadLine().ToCharArray();
            }

            public string ReadString()
            {
                return this.ReadLine();
            }

            public Int64[] ReadInt64Array()
            {
                return this.ReadLine().Split(Separator).Select(Int64.Parse).ToArray();
            }

            public Double[] ReadDoubleArray()
            {
                return this.ReadLine().Split(Separator).Select(Double.Parse).ToArray();
            }
        }

        private abstract class SolverBase
        {
            protected readonly ExtendedReader _reader;
            protected readonly TextWriter _writer;

            protected SolverBase()
            {
#if DEBUG
                _reader = new ExtendedReader(@"input.txt");
                //_writer = new StreamWriter(@"output.txt");
                _writer = new StreamWriter(Console.OpenStandardOutput());
#else
                _reader = new ExtendedReader(Console.OpenStandardInput());
                _writer = new StreamWriter(Console.OpenStandardOutput());
#endif
            }

            public abstract Solver Solve();

            public abstract void OutputResult();
        }

        private class Solver : SolverBase
        {
            private long result = 0;

            public override Solver Solve()
            {
                // link to task: http://codeforces.com/problemset/problem/681/C

                var input = _reader.ReadIntArray();
                var n = input[0];
                var m = input[1];
                var numbers = new HashSet<int>();
                var maxN = GetMax(n - 1);
                var maxM = GetMax(m - 1);

                if (maxN + maxM > 7)
                {
                    return this;
                }

                for (int i = 0; i < n; i++)
                {
                    numbers.Clear();
                    if (!ToSeven(i, maxN, numbers)) continue;

                    for (int j = 0; j < m; j++)
                    {
                        if (i == j) continue;
                        numbers.Clear();
                        if (ToSeven(i, maxN, numbers) && ToSeven(j, maxM, numbers))
                        {
                            result++;
                        }
                    }
                }

                return this;
            }

            private int GetMax(int val)
            {
                int i = 0;
                do
                {
                    i++;
                    val /= 7;
                } while (val > 0);
                return i;
            }

            private bool ToSeven(int val, int max, HashSet<int> nums)
            {
                for (int i = max - 1; i >= 0; i--)
                {
                    var value = val % 7;
                    if (nums.Contains(value)) return false;
                    val /= 7;
                    nums.Add(value);
                }

                return true;
            }

            public override void OutputResult()
            {
                string answer = result.ToString();

                _writer.WriteLine(answer);
                _writer.Dispose();
            }
        }
    }
}

using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;

namespace Codeforces
{
    internal class Template
    {
        private void Solve()
        {
            var n = cin.NextInt();
            var m = cin.NextInt();

            var maxN = IntToString(n - 1);
            var maxM = IntToString(m - 1);

            var length = maxN.Length + maxM.Length;
            if (length > 7)
            {
                Console.WriteLine(0);
                return;
            }

            var nn = long.Parse(maxN);
            var mm = long.Parse(maxM);

            //var max = 7;
            //for (var i = 1; i < length; i++)
            //{
            //    max *= 10;
            //}

            //var digits = new HashSet<int>();
            //var cnt = 0;
            //for (var i = 0; i < max; i++)
            //{
            //    digits.Clear();
            //    var ok = true;
            //    var num = i;
            //    while (num > 0)
            //    {
            //        var rem = num%10;
            //        if (rem > 6)
            //        {
            //            ok = false;
            //            break;
            //        }
            //        if (digits.Contains(rem))
            //        {
            //            ok = false;
            //            break;
            //        }
            //        digits.Add(rem);
            //        num /= 10;
            //    }
            //    if (!ok)
            //    {
            //        continue;
            //    }

            //    if (length == digits.Count)
            //    {
            //        var str = i.ToString();
            //        var first = str.Substring(0, maxN.Length);
            //        var second = str.Substring(maxN.Length);
            //        if (long.Parse(first) <= nn && long.Parse(second) <= mm)
            //        {
            //            cnt++;
            //        }
            //    }
            //    else if (length - digits.Count == 1 && !digits.Contains(0))
            //    {
            //        var str = "0" + i.ToString();
            //        var first = str.Substring(0, maxN.Length);
            //        var second = str.Substring(maxN.Length);
            //        if (long.Parse(first) <= nn && long.Parse(second) <= mm)
            //        {
            //            cnt++;
            //        }
            //    }
            //}

            //Console.WriteLine(cnt);

            //return;

            var count = 0;
            var chars = new List<char>();
            for (var i = 0; i < n; i++)
            {
                var hasZero = false;

                var num = IntToString(i);
                if (num.Length < maxN.Length)
                {
                    if (maxN.Length - num.Length == 1)
                    {
                        if (!num.Contains('0'))
                        {
                            hasZero = true;
                        }
                        else
                        {
                            continue;
                        }
                    }
                    else
                    {
                        continue;
                    }
                }
                if (num.Distinct().Count() != num.Length)
                {
                    continue;
                }

                chars.Clear();
                if (!hasZero && !num.Contains('0'))
                {
                    chars.Add('0');
                }

                for (var c = '1'; c <= '6'; c++)
                {
                    if (!num.Contains(c))
                    {
                        chars.Add(c);
                    }
                }

                var unique = new HashSet<string>();
                do
                {
                    var str = new string(chars.ToArray()).Substring(0, maxM.Length);
                    if (!unique.Contains(str))
                    {
                        unique.Add(str);
                        var value = long.Parse(str);
                        if (value <= mm)
                        {
                            count++;
                        }
                    }
                } while (NextPermutation(chars));
            }

            Console.WriteLine(count);

        }

        private static readonly char[] baseChars = new[] {'0', '1', '2', '3', '4', '5', '6'};

        public static string IntToString(int value)
        {
            string result = string.Empty;
            int targetBase = baseChars.Length;

            do
            {
                result = baseChars[value % targetBase] + result;
                value = value / targetBase;
            }
            while (value > 0);

            return result;
        }

        public static bool NextPermutation<T>(IList<T> items) where T : IComparable
        {
            var i = -1;
            for (var x = items.Count - 2; x >= 0; x--)
            {
                if (items[x].CompareTo(items[x + 1]) < 0)
                {
                    i = x;
                    break;
                }
            }

            if (i == -1)
            {
                return false;
            }
            var j = 0;
            for (var x = items.Count - 1; x > i; x--)
            {
                if (items[x].CompareTo(items[i]) > 0)
                {
                    j = x;
                    break;
                }
            }
            var temp = items[i];
            items[i] = items[j];
            items[j] = temp;
            //Array.Reverse(items, i + 1, items.Count - (i + 1));
            var index = i + 1;
            var endIndex = index + items.Count - (i + 1) - 1;
            while (index < endIndex)
            {
                temp = items[index];
                items[index] = items[endIndex];
                items[endIndex] = temp;
                index++;
                endIndex--;
            }
            return true;
        }

        private static readonly Scanner cin = new Scanner();

        private static void Main()
        {
#if DEBUG
            var inputText = File.ReadAllText(@"..\..\input.txt");
            var testCases = inputText.Split(new[] { "input" }, StringSplitOptions.RemoveEmptyEntries);
            var consoleOut = Console.Out;
            for (var i = 0; i < testCases.Length; i++)
            {
                var parts = testCases[i].Split(new[] { "output" }, StringSplitOptions.RemoveEmptyEntries);
                Console.SetIn(new StringReader(parts[0].Trim()));
                var stringWriter = new StringWriter();
                Console.SetOut(stringWriter);
                var sw = Stopwatch.StartNew();
                new Template().Solve();
                sw.Stop();
                var output = stringWriter.ToString();

                Console.SetOut(consoleOut);
                var color = ConsoleColor.Green;
                var status = "Passed";
                if (parts[1].Trim() != output.Trim())
                {
                    color = ConsoleColor.Red;
                    status = "Failed";
                }
                Console.ForegroundColor = color;
                Console.WriteLine("Test {0} {1} in {2}ms", i + 1, status, sw.ElapsedMilliseconds);
            }
            Console.ReadLine();
            Console.ReadKey();
#else
			new Template().Solve();
			Console.ReadLine();
#endif
        }
    }

    internal class Scanner
    {
        private string[] s = new string[0];
        private int i;
        private readonly char[] cs = { ' ' };

        public string NextString()
        {
            if (i < s.Length) return s[i++];
            var line = Console.ReadLine() ?? string.Empty;
            s = line.Split(cs, StringSplitOptions.RemoveEmptyEntries);
            i = 1;
            return s.First();
        }

        public double NextDouble()
        {
            return double.Parse(NextString());
        }

        public int NextInt()
        {
            return int.Parse(NextString());
        }

        public long NextLong()
        {
            return long.Parse(NextString());
        }
    }
}

using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;

namespace Codeforces
{
    internal class Template
    {
        private void Solve()
        {
            var n = cin.NextInt();
            var m = cin.NextInt();

            var maxN = IntToString(n - 1);
            var maxM = IntToString(m - 1);

            var length = maxN.Length + maxM.Length;
            if (length > 7)
            {
                Console.WriteLine(0);
                return;
            }

            var nn = long.Parse(maxN);
            var mm = long.Parse(maxM);

            var max = 7;
            for (var i = 1; i < length; i++)
            {
                max *= 10;
            }

            var digits = new HashSet<int>();
            var cnt = 0;
            for (var i = 0; i < max; i++)
            {
                digits.Clear();
                var ok = true;
                var num = i;
                while (num > 0)
                {
                    var rem = num%10;
                    if (rem > 6)
                    {
                        ok = false;
                        break;
                    }
                    if (digits.Contains(rem))
                    {
                        ok = false;
                        break;
                    }
                    digits.Add(rem);
                    num /= 10;
                }
                if (!ok)
                {
                    continue;
                }

                if (length == digits.Count)
                {
                    var str = i.ToString();
                    var first = str.Substring(0, maxN.Length);
                    var second = str.Substring(maxN.Length);
                    if (long.Parse(first) <= nn && long.Parse(second) <= mm)
                    {
                        cnt++;
                    }
                }
                else if (length - digits.Count == 1 && !digits.Contains(0))
                {
                    var str = "0" + i.ToString();
                    var first = str.Substring(0, maxN.Length);
                    var second = str.Substring(maxN.Length);
                    if (long.Parse(first) <= nn && long.Parse(second) <= mm)
                    {
                        cnt++;
                    }
                }
            }

            Console.WriteLine(cnt);

            return;

            var count = 0;
            var chars = new List<char>();
            for (var i = 0; i < n; i++)
            {
                var hasZero = false;

                var num = IntToString(i);
                if (num.Length < maxN.Length)
                {
                    if (maxN.Length - num.Length == 1)
                    {
                        if (!num.Contains('0'))
                        {
                            hasZero = true;
                        }
                        else
                        {
                            continue;
                        }
                    }
                    else
                    {
                        continue;
                    }
                }

                chars.Clear();
                if (!hasZero && !num.Contains('0'))
                {
                    chars.Add('0');
                }

                for (var c = '1'; c <= '6'; c++)
                {
                    if (!num.Contains(c))
                    {
                        chars.Add(c);
                    }
                }

                var unique = new HashSet<string>();
                do
                {
                    var str = new string(chars.ToArray()).Substring(0, maxM.Length);
                    if (!unique.Contains(str))
                    {
                        unique.Add(str);
                        var value = long.Parse(str);
                        if (value <= mm)
                        {
                            count++;
                        }
                    }
                } while (NextPermutation(chars));
            }

            Console.WriteLine(count);

        }

        private static readonly char[] baseChars = new[] {'0', '1', '2', '3', '4', '5', '6'};

        public static string IntToString(int value)
        {
            string result = string.Empty;
            int targetBase = baseChars.Length;

            do
            {
                result = baseChars[value % targetBase] + result;
                value = value / targetBase;
            }
            while (value > 0);

            return result;
        }

        public static bool NextPermutation<T>(IList<T> items) where T : IComparable
        {
            var i = -1;
            for (var x = items.Count - 2; x >= 0; x--)
            {
                if (items[x].CompareTo(items[x + 1]) < 0)
                {
                    i = x;
                    break;
                }
            }

            if (i == -1)
            {
                return false;
            }
            var j = 0;
            for (var x = items.Count - 1; x > i; x--)
            {
                if (items[x].CompareTo(items[i]) > 0)
                {
                    j = x;
                    break;
                }
            }
            var temp = items[i];
            items[i] = items[j];
            items[j] = temp;
            //Array.Reverse(items, i + 1, items.Count - (i + 1));
            var index = i + 1;
            var endIndex = index + items.Count - (i + 1) - 1;
            while (index < endIndex)
            {
                temp = items[index];
                items[index] = items[endIndex];
                items[endIndex] = temp;
                index++;
                endIndex--;
            }
            return true;
        }

        private static readonly Scanner cin = new Scanner();

        private static void Main()
        {
#if DEBUG
            var inputText = File.ReadAllText(@"..\..\input.txt");
            var testCases = inputText.Split(new[] { "input" }, StringSplitOptions.RemoveEmptyEntries);
            var consoleOut = Console.Out;
            for (var i = 0; i < testCases.Length; i++)
            {
                var parts = testCases[i].Split(new[] { "output" }, StringSplitOptions.RemoveEmptyEntries);
                Console.SetIn(new StringReader(parts[0].Trim()));
                var stringWriter = new StringWriter();
                Console.SetOut(stringWriter);
                var sw = Stopwatch.StartNew();
                new Template().Solve();
                sw.Stop();
                var output = stringWriter.ToString();

                Console.SetOut(consoleOut);
                var color = ConsoleColor.Green;
                var status = "Passed";
                if (parts[1].Trim() != output.Trim())
                {
                    color = ConsoleColor.Red;
                    status = "Failed";
                }
                Console.ForegroundColor = color;
                Console.WriteLine("Test {0} {1} in {2}ms", i + 1, status, sw.ElapsedMilliseconds);
            }
            Console.ReadLine();
            Console.ReadKey();
#else
			new Template().Solve();
			Console.ReadLine();
#endif
        }
    }

    internal class Scanner
    {
        private string[] s = new string[0];
        private int i;
        private readonly char[] cs = { ' ' };

        public string NextString()
        {
            if (i < s.Length) return s[i++];
            var line = Console.ReadLine() ?? string.Empty;
            s = line.Split(cs, StringSplitOptions.RemoveEmptyEntries);
            i = 1;
            return s.First();
        }

        public double NextDouble()
        {
            return double.Parse(NextString());
        }

        public int NextInt()
        {
            return int.Parse(NextString());
        }

        public long NextLong()
        {
            return long.Parse(NextString());
        }
    }
}

using System;
using System.Linq;

namespace ConsoleApplication45
{
    class Program
    {
        static void Main(string[] args)
        {
            Reader input = new Reader();
            const int BASE = 7;
            int n = input.GiveNext(), m = input.GiveNext();
            int len1 = 1, len2 = 1;
            for (int i = BASE; i < n; i *= BASE) len1++;
            for (int i = BASE; i < m; i *= BASE) len2++;
            int ans = 0;
            if (len1 + len2 <= 7)
                for (int hour = 0; hour < n; hour++)
                    for (int minute = 0; minute < m; minute++)
                    {
                        int[] digits = new int[BASE];
                        for (int current_hour = hour, k = 0; k != len1; current_hour /= BASE, k++)
                            digits[current_hour % BASE]++;
                        for (int current_minute = minute, k = 0; k != len2; current_minute /= BASE, k++)
                            digits[current_minute % BASE]++;
                        if (digits.Max() <= 1) ans++;
                    }
            Console.WriteLine(ans);
            Console.ReadLine();
        }
    }
    class Reader
    {
        string[] elements;
        int i;
        public int GiveNext()
        {
            string ans;
            if (elements == null || i == elements.Length)
            {
                elements = Console.ReadLine().Split(' ');
                ans = elements[0];
                i = 1;
            }
            else
            {
                ans = elements[i];
                i++;
            }
            return int.Parse(ans);
        }
    }
}

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

internal class Program
{
    public static int GetMaxDigitsOf7CC(int n)
    {
        int ret = 0;
        if (n == 0)
            return 1;
        while (n != 0)
        {
            ret++;
            n /= 7;
        }
        return ret;
    }

    private static void Main(string[] args)
    {
        int ans = 0;
        var inp = (Console.ReadLine()).Split(' ').Select(int.Parse).ToArray();
        var h = inp[0];
        var m = inp[1];
        var hr = GetMaxDigitsOf7CC(h - 1);
        var mr = GetMaxDigitsOf7CC(m - 1);
        if (hr + mr > 7)
            Console.WriteLine("0");
        else
        {
            for (int i = 0; i < h; i++)
            {
                for (int j = 0; j < m; j++)
                {
                    int[] mas = new int[7];
                    bool is_ok = true;
                    //-----------h
                    int tmp = i;
                    for (int z1 = 0; z1 < hr; z1++)
                    {
                        int ost = tmp % 7;
                        mas[ost]++;
                        if (mas[ost] > 1)
                        {
                            is_ok = false;
                            break;
                        }
                        tmp /= 7;
                    }
                    //---------m
                    tmp = j;
                    for (int z2 = 0; z2 < mr; z2++)
                    {
                        int ost = tmp % 7;
                        mas[ost]++;
                        if (mas[ost] > 1)
                        {
                            is_ok = false;
                            break;
                        }
                        tmp /= 7;
                    }
                    if (is_ok == true)
                    {
                        //Console.WriteLine("{0} {1}", i, j);
                        ans++;
                    }
                }
            }
            Console.WriteLine("{0}", ans);
        }
        //Console.ReadKey();
    }
}

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

namespace _686C
{
    class Program
    {
        static int[] powers7 = new[] { 7, 49, 343, 2401, 16807, 117649, 823543, 5764801, 40353607, 282475249 };

        static void Main(string[] args)
        {
            string[] input = Console.ReadLine().Split(' ');
            int n = int.Parse(input[0]), m = int.Parse(input[1]);
            long answer = 0;
            int firstDigits = 1, secondDigits = 1;
            for (var a = 7; a < n; a *= 7)
                firstDigits += 1;
            for (var b = 7; b < m; b *= 7)
                secondDigits += 1;

            if (firstDigits + secondDigits <= 7)
            {
                for (int i = 0; i < n; i++)
                {
                    for (int j = 0; j < m; j++)
                    {
                        int[] used = new int[7];
                        for (int a = i, k = 0; k != firstDigits; a /= 7, k++)
                            used[a % 7]++;
                        for (int b = j, k = 0; k != secondDigits; b /= 7, k++)
                            used[b % 7]++;

                        if (used.Max() <= 1) answer++;
                    }
                }
            }

            Console.WriteLine(answer);
            //Console.ReadLine();
        }
    }
}

using System;
using System.Globalization;
using System.IO;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;
using System.Threading;

namespace Codeforces
{
    class Program : ProgramBase
    {
        private const long commonMod = 1000000007;

        static void Main(string[] args)
        {
            var p = new Program();
            var x = p.Get();
            p.Out(x);
        }

        object Get()
        {
            checked
            {
                //FileName = "input";
                var n = ReadLongToken();
                var m = ReadLongToken();
                var nlog = logbase7(n);
                var mlog = logbase7(m);
                if (nlog + mlog > 7)
                    return 0;
                var hour = new int[nlog];
                var mins = new int[mlog];
                var counts = new int[7];
                counts[0] = (nlog + mlog);
                var bads = 1;
                var result = 0;
                for (int i = 0; i < n; i++)
                {
                    for (int j = 0; j < m; j++)
                    {
                        if (bads == 0)
                            result++;
                        int digit = 0;
                        while (digit < mlog)
                        {
                            if (mins[digit] < 6)
                            {
                                counts[mins[digit]]--;
                                if (counts[mins[digit]] == 1)
                                    bads--;
                                mins[digit]++;
                                counts[mins[digit]]++;
                                if (counts[mins[digit]] == 2)
                                    bads++;
                                break;
                            }
                            else
                            {
                                counts[mins[digit]]--;
                                if (counts[mins[digit]] == 1)
                                    bads--;
                                mins[digit] = 0;
                                counts[mins[digit]]++;
                                if (counts[mins[digit]] == 2)
                                    bads++;
                            }
                            digit++;
                        }
                    }
                    for (int z = 0; z < mlog; z++)
                    {
                        counts[mins[z]]--;
                        if (counts[mins[z]] == 1)
                            bads--;
                        mins[z] = 0;
                        counts[mins[z]]++;
                        if (counts[mins[z]] == 2)
                            bads++;
                    }
                    var d = 0;
                    while (d < nlog)
                    {
                        if (hour[d] < 6)
                        {
                            counts[hour[d]]--;
                            if (counts[hour[d]] == 1)
                                bads--;
                            hour[d]++;
                            counts[hour[d]]++;
                            if (counts[hour[d]] == 2)
                                bads++;
                            break;
                        }
                        else
                        {
                            counts[hour[d]]--;
                            if (counts[hour[d]] == 1)
                                bads--;
                            hour[d] = 0;
                            counts[hour[d]]++;
                            if (counts[hour[d]] == 2)
                                bads++;
                        }
                        d++;
                    }

                }
                return result;
            }

        }

        public int logbase7(long v)
        {
            if (v <= 1)
                return 1;
            var res = 0;
            v = v - 1;
            while (v > 0)
            {
                v /= 7;
                res++;
            }
            return res;
        }

        public static class Struct
        {
            public static Pair<T1, T2> Create<T1, T2>(T1 item1, T2 item2)
            {
                return new Pair<T1, T2> { Item1 = item1, Item2 = item2 };
            }
        }

        public struct Pair<T1, T2>
        {
            public T1 Item1 { get; set; }
            public T2 Item2 { get; set; }
        }

        class Automata
        {
            bool[] terminals;
            public int sigma;
            public int len;
            public int[,] jumps;

            public void Create()
            {
                var a = ReadInts();
                len = a[0];
                sigma = a[2];
                var ts = ReadInts();
                terminals = new bool[len];
                for (int i = 0; i < ts.Length; i++)
                    terminals[ts[i]] = true;
                jumps = new int[len, sigma];
                for (int i = 0; i < len * sigma; i++)
                {
                    var b = Console.ReadLine().Split(' ');
                    jumps[Convert.ToInt32(b[0]), b[1][0] - 'a'] = Convert.ToInt32(b[2]);
                }
            }
            protected int[] ReadInts()
            {
                return Console.ReadLine().Split(' ').Select(x => Convert.ToInt32(x)).ToArray();
            }

            public bool IsTerminal(int s)
            {
                return terminals[s];
            }
        }
    }

    abstract class ProgramBase
    {
        bool? prod = null;
        StreamReader f;
        Queue<string> tokens;
        protected string FileName { private get; set; }

        protected string Read()
        {
            if (f == null)
                f = string.IsNullOrEmpty(FileName)
                    ? new StreamReader(Console.OpenStandardInput())
                    : new StreamReader((GetProd() ? "" : "c:\\dev\\") + FileName);
            return f.ReadLine();
        }

        protected int ReadInt()
        {
            return int.Parse(Read());
        }

        protected int ReadIntToken()
        {
            if (tokens == null || tokens.Count == 0)
                tokens = new Queue<string>(Read().Split(' '));
            return int.Parse(tokens.Dequeue());
        }

        protected int[] ReadInts()
        {
            var tokens = Read().Split(' ');
            var result = new int[tokens.Length];
            for (int i = 0; i < tokens.Length; i++)
                result[i] = int.Parse(tokens[i]);
            return result;
        }

        protected long ReadLongToken()
        {
            if (tokens == null || tokens.Count == 0)
                tokens = new Queue<string>(Read().Split(' '));
            return long.Parse(tokens.Dequeue());
        }

        protected long ReadLong()
        {
            return Convert.ToInt64(Read());
        }

        protected long[] ReadLongs()
        {
            var tokens = Read().Split(' ');
            var result = new long[tokens.Length];
            for (int i = 0; i < tokens.Length; i++)
                result[i] = long.Parse(tokens[i]);
            return result;
        }

        public void Out(object r)
        {
            if (string.IsNullOrEmpty(FileName))
                Console.WriteLine(r);
            else if (GetProd())
                File.WriteAllText(FileName, r.ToString());
            else
                Console.WriteLine(r);
        }

        private bool GetProd()
        {

            if (!prod.HasValue)
                try
                {
                    prod = Environment.MachineName != "RENADEEN-W7";
                }
                catch (Exception)
                {
                    prod = true;
                }
            return prod.Value;
        }
    }

    public static class Huj
    {
        public static T MinBy<T>(this IEnumerable<T> source, Func<T, double> func) where T : class
        {
            T result = null;
            var min = double.MaxValue;
            foreach (var item in source)
            {
                var current = func(item);
                if (min > current)
                {
                    min = current;
                    result = item;
                }
            }
            return result;
        }

        public static T MaxBy<T>(this IEnumerable<T> source, Func<T, double> func, T defaultValue = default(T))
        {
            T result = defaultValue;
            var max = double.MinValue;
            foreach (var item in source)
            {
                var current = func(item);
                if (max < current)
                {
                    max = current;
                    result = item;
                }
            }
            return result;
        }

        public static string JoinStrings(this IEnumerable<string> source, string delimeter)
        {
            return string.Join(delimeter, source.ToArray());
        }

        public static string JoinStrings(this IEnumerable<int> source, string delimeter)
        {
            return source.Select(x => x.ToString()).JoinStrings(delimeter);
        }
    }
}

using System;
using System.Globalization;
using System.IO;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;
using System.Threading;

namespace Codeforces
{
    class Program : ProgramBase
    {
        private const long commonMod = 1000000007;

        static void Main(string[] args)
        {
            var p = new Program();
            var x = p.Get();
            p.Out(x);
        }

        object Get()
        {
            checked
            {
                //FileName = "input";
                var n = ReadLongToken();
                var m = ReadLongToken();
                var nlog = logbase7(n);
                var mlog = logbase7(m);
                if (nlog + mlog > 7)
                    return 0;
                var hour = new int[nlog];
                var mins = new int[mlog];
                var result = 0;
                for (int i = 0; i < n; i++)
                {
                    for (int j = 0; j < m; j++)
                    {
                        if (Check(hour, mins))
                            result++;
                        int digit = 0;
                        while (digit < mlog)
                        {
                            if (mins[digit] < 6)
                            {
                                mins[digit]++;
                                break;
                            }
                            else
                                mins[digit] = 0;
                            digit++;
                        }
                    }
                    for (int z = 0; z < mlog; z++)
                        mins[z] = 0;
                    var d = 0;
                    while (d < nlog)
                    {
                        if (hour[d] < 6)
                        {
                            hour[d]++;
                            break;
                        }
                        else
                            hour[d] = 0;
                        d++;
                    }

                }
                return result;
            }
        }

        bool Check(int[] hour, int[] mins)
        {
            bool[] set = new bool[7];
            for (int i = 0; i < hour.Length; i++)
                if (set[hour[i]] == true)
                    return false;
                else
                    set[hour[i]] = true;
            for (int i = 0; i < mins.Length; i++)
                if (set[mins[i]] == true)
                    return false;
                else
                    set[mins[i]] = true;
            return true;
        }

        public int logbase7(long v)
        {
            if (v <= 1)
                return 1;
            var res = 0;
            v = v - 1;
            while (v > 0)
            {
                v /= 7;
                res++;
            }
            return res;
        }

        public static class Struct
        {
            public static Pair<T1, T2> Create<T1, T2>(T1 item1, T2 item2)
            {
                return new Pair<T1, T2> { Item1 = item1, Item2 = item2 };
            }
        }

        public struct Pair<T1, T2>
        {
            public T1 Item1 { get; set; }
            public T2 Item2 { get; set; }
        }

        class Automata
        {
            bool[] terminals;
            public int sigma;
            public int len;
            public int[,] jumps;

            public void Create()
            {
                var a = ReadInts();
                len = a[0];
                sigma = a[2];
                var ts = ReadInts();
                terminals = new bool[len];
                for (int i = 0; i < ts.Length; i++)
                    terminals[ts[i]] = true;
                jumps = new int[len, sigma];
                for (int i = 0; i < len * sigma; i++)
                {
                    var b = Console.ReadLine().Split(' ');
                    jumps[Convert.ToInt32(b[0]), b[1][0] - 'a'] = Convert.ToInt32(b[2]);
                }
            }
            protected int[] ReadInts()
            {
                return Console.ReadLine().Split(' ').Select(x => Convert.ToInt32(x)).ToArray();
            }

            public bool IsTerminal(int s)
            {
                return terminals[s];
            }
        }
    }

    abstract class ProgramBase
    {
        bool? prod = null;
        StreamReader f;
        Queue<string> tokens;
        protected string FileName { private get; set; }

        protected string Read()
        {
            if (f == null)
                f = string.IsNullOrEmpty(FileName)
                    ? new StreamReader(Console.OpenStandardInput())
                    : new StreamReader((GetProd() ? "" : "c:\\dev\\") + FileName);
            return f.ReadLine();
        }

        protected int ReadInt()
        {
            return int.Parse(Read());
        }

        protected int ReadIntToken()
        {
            if (tokens == null || tokens.Count == 0)
                tokens = new Queue<string>(Read().Split(' '));
            return int.Parse(tokens.Dequeue());
        }

        protected int[] ReadInts()
        {
            var tokens = Read().Split(' ');
            var result = new int[tokens.Length];
            for (int i = 0; i < tokens.Length; i++)
                result[i] = int.Parse(tokens[i]);
            return result;
        }

        protected long ReadLongToken()
        {
            if (tokens == null || tokens.Count == 0)
                tokens = new Queue<string>(Read().Split(' '));
            return long.Parse(tokens.Dequeue());
        }

        protected long ReadLong()
        {
            return Convert.ToInt64(Read());
        }

        protected long[] ReadLongs()
        {
            var tokens = Read().Split(' ');
            var result = new long[tokens.Length];
            for (int i = 0; i < tokens.Length; i++)
                result[i] = long.Parse(tokens[i]);
            return result;
        }

        public void Out(object r)
        {
            if (string.IsNullOrEmpty(FileName))
                Console.WriteLine(r);
            else if (GetProd())
                File.WriteAllText(FileName, r.ToString());
            else
                Console.WriteLine(r);
        }

        private bool GetProd()
        {

            if (!prod.HasValue)
                try
                {
                    prod = Environment.MachineName != "RENADEEN-W7";
                }
                catch (Exception)
                {
                    prod = true;
                }
            return prod.Value;
        }
    }

    public static class Huj
    {
        public static T MinBy<T>(this IEnumerable<T> source, Func<T, double> func) where T : class
        {
            T result = null;
            var min = double.MaxValue;
            foreach (var item in source)
            {
                var current = func(item);
                if (min > current)
                {
                    min = current;
                    result = item;
                }
            }
            return result;
        }

        public static T MaxBy<T>(this IEnumerable<T> source, Func<T, double> func, T defaultValue = default(T))
        {
            T result = defaultValue;
            var max = double.MinValue;
            foreach (var item in source)
            {
                var current = func(item);
                if (max < current)
                {
                    max = current;
                    result = item;
                }
            }
            return result;
        }

        public static string JoinStrings(this IEnumerable<string> source, string delimeter)
        {
            return string.Join(delimeter, source.ToArray());
        }

        public static string JoinStrings(this IEnumerable<int> source, string delimeter)
        {
            return source.Select(x => x.ToString()).JoinStrings(delimeter);
        }
    }
}

using System;
using System.Globalization;
using System.IO;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;
using System.Threading;

namespace Codeforces
{
    class Program : ProgramBase
    {
        private const long commonMod = 1000000007;

        static void Main(string[] args)
        {
            var p = new Program();
            var x = p.Get();
            p.Out(x);
        }

        object Get()
        {
            checked
            {
                //FileName = "input";
                var n = ReadLongToken();
                var m = ReadLongToken();
                var nlog = logbase7(n);
                var mlog = logbase7(m);
                if (nlog + mlog > 7)
                    return 0;
                var log = nlog + mlog;

                var result = 0;

                var a = new int[7] { 0, 1, 2, 3, 4, 5, 6 };
                int[] prev = new int[7];
                do
                {
                    if (prev != null)
                    {
                        var fl = true;
                        for (int i = 0; i < log; i++)
                        {
                            if (a[i] != prev[i])
                            {
                                fl = false;
                                break;
                            }
                        }
                        if (fl)
                        {
                            continue;
                        }
                    }
                    var v = 0;
                    var pow = 1;
                    for (int i = 0; i < nlog; i++)
                    {
                        v += a[i] * pow;
                        pow *= 7;
                    }
                    if (v >= n)
                    {
                        Array.Copy(a, prev, 7);
                        continue;
                    }

                    pow = 1;
                    v = 0;
                    for (int i = 0; i < mlog; i++)
                    {
                        v += a[nlog + i] * pow;
                        pow *= 7;
                    }
                    if (v >= m)
                    {
                        Array.Copy(a, prev, 7);
                        continue;
                    }
                    result++;
                    Array.Copy(a, prev, 7);
                } while (NextPermutation(a));
                return result;
            }

        }
        private static bool NextPermutation(int[] numList)
        {
            /*
             Knuths
             1. Find the largest index j such that a[j] < a[j + 1]. If no such index exists, the permutation is the last permutation.
             2. Find the largest index l such that a[j] < a[l]. Since j + 1 is such an index, l is well defined and satisfies j < l.
             3. Swap a[j] with a[l].
             4. Reverse the sequence from a[j + 1] up to and including the final element a[n].

             */
            var largestIndex = -1;
            for (var i = numList.Length - 2; i >= 0; i--)
            {
                if (numList[i] < numList[i + 1])
                {
                    largestIndex = i;
                    break;
                }
            }

            if (largestIndex < 0) return false;

            var largestIndex2 = -1;
            for (var i = numList.Length - 1; i >= 0; i--)
            {
                if (numList[largestIndex] < numList[i])
                {
                    largestIndex2 = i;
                    break;
                }
            }

            var tmp = numList[largestIndex];
            numList[largestIndex] = numList[largestIndex2];
            numList[largestIndex2] = tmp;

            for (int i = largestIndex + 1, j = numList.Length - 1; i < j; i++, j--)
            {
                tmp = numList[i];
                numList[i] = numList[j];
                numList[j] = tmp;
            }

            return true;
        }

        public int logbase7(long v)
        {
            if (v <= 1)
                return 1;
            var res = 0;
            v = v - 1;
            while(v > 0)
            {
                v /= 7;
                res++;
            }
            return res;
        }

        public static class Struct
        {
            public static Pair<T1, T2> Create<T1,T2>(T1 item1, T2 item2)
            {
                return new Pair<T1, T2> { Item1 = item1, Item2 = item2 };
            }
        }

        public struct Pair<T1, T2>
        {
            public T1 Item1 { get; set; }
            public T2 Item2 { get; set; }
        }

        class Automata
        {
            bool[] terminals;
            public int sigma;
            public int len;
            public int[,] jumps;

            public void Create()
            {
                var a = ReadInts();
                len = a[0];
                sigma = a[2];
                var ts = ReadInts();
                terminals = new bool[len];
                for (int i = 0; i < ts.Length; i++)
                    terminals[ts[i]] = true;
                jumps = new int[len, sigma];
                for (int i = 0; i < len * sigma; i++)
                {
                    var b = Console.ReadLine().Split(' ');
                    jumps[Convert.ToInt32(b[0]), b[1][0] - 'a'] = Convert.ToInt32(b[2]);
                }
            }
            protected int[] ReadInts()
            {
                return Console.ReadLine().Split(' ').Select(x => Convert.ToInt32(x)).ToArray();
            }

            public bool IsTerminal(int s)
            {
                return terminals[s];
            }
        }
    }

    abstract class ProgramBase
    {
        bool? prod = null;
        StreamReader f;
        Queue<string> tokens;
        protected string FileName { private get; set; }

        protected string Read()
        {
            if (f == null)
                f = string.IsNullOrEmpty(FileName)
                    ? new StreamReader(Console.OpenStandardInput())
                    : new StreamReader((GetProd() ? "" : "c:\\dev\\") + FileName);
            return f.ReadLine();
        }

        protected int ReadInt()
        {
            return int.Parse(Read());
        }

        protected int ReadIntToken()
        {
            if (tokens == null || tokens.Count == 0)
                tokens = new Queue<string>(Read().Split(' '));
            return int.Parse(tokens.Dequeue());
        }

        protected int[] ReadInts()
        {
            var tokens = Read().Split(' ');
            var result = new int[tokens.Length];
            for (int i = 0; i < tokens.Length; i++)
                result[i] = int.Parse(tokens[i]);
            return result;
        }

        protected long ReadLongToken()
        {
            if (tokens == null || tokens.Count == 0)
                tokens = new Queue<string>(Read().Split(' '));
            return long.Parse(tokens.Dequeue());
        }

        protected long ReadLong()
        {
            return Convert.ToInt64(Read());
        }

        protected long[] ReadLongs()
        {
            var tokens = Read().Split(' ');
            var result = new long[tokens.Length];
            for (int i = 0; i < tokens.Length; i++)
                result[i] = long.Parse(tokens[i]);
            return result;
        }

        public void Out(object r)
        {
            if (string.IsNullOrEmpty(FileName))
                Console.WriteLine(r);
            else if (GetProd())
                File.WriteAllText(FileName, r.ToString());
            else
                Console.WriteLine(r);
        }

        private bool GetProd()
        {

            if (!prod.HasValue)
                try
                {
                    prod = Environment.MachineName != "RENADEEN-W7";
                }
                catch (Exception)
                {
                    prod = true;
                }
            return prod.Value;
        }
    }

    public static class Huj
    {
        public static T MinBy<T>(this IEnumerable<T> source, Func<T, double> func) where T : class
        {
            T result = null;
            var min = double.MaxValue;
            foreach (var item in source)
            {
                var current = func(item);
                if (min > current)
                {
                    min = current;
                    result = item;
                }
            }
            return result;
        }

        public static T MaxBy<T>(this IEnumerable<T> source, Func<T, double> func, T defaultValue = default(T))
        {
            T result = defaultValue;
            var max = double.MinValue;
            foreach (var item in source)
            {
                var current = func(item);
                if (max < current)
                {
                    max = current;
                    result = item;
                }
            }
            return result;
        }

        public static string JoinStrings(this IEnumerable<string> source, string delimeter)
        {
            return string.Join(delimeter, source.ToArray());
        }

        public static string JoinStrings(this IEnumerable<int> source, string delimeter)
        {
            return source.Select(x => x.ToString()).JoinStrings(delimeter);
        }
    }
}

using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;

namespace CF317
{
	internal class Program
	{
		private static void Main(string[] args)
		{
			var sr = new InputReader(Console.In);
			//var sr = new InputReader(new StreamReader("input.txt"));
			var task = new Task();
			using (var sw = Console.Out)
			//using (var sw = new StreamWriter("output.txt"))
			{
				task.Solve(sr, sw);
				//Console.ReadKey();
			}
		}
	}

	internal class Task
	{
		private long result = 0L;
		private List<int> daysInSeven;
		private List<int> minsInSeven;
		private string firstStr;
		private string secondStr;

		public void Solve(InputReader sr, TextWriter sw)
		{
			var input = sr.ReadArray(Int64.Parse);
			var n = input[0] - 1;
			var m = input[1] - 1;
			daysInSeven = ToSevenBase(n);
			minsInSeven = ToSevenBase(m);
			var reversed = daysInSeven.ToArray().Reverse();
			firstStr = reversed.Aggregate("", (curr, item) => curr + item);
			reversed = minsInSeven.ToArray().Reverse();
			secondStr = reversed.Aggregate("", (curr, item) => curr + item);
			var leftCount = daysInSeven.Count;
			var rightCount = minsInSeven.Count;
			if (leftCount + rightCount > 7) {
				sw.WriteLine(0);
				return;
			}
			if (rightCount < 0) {
				rightCount = 0;
			}
			Generate(0, 0, leftCount, rightCount, leftCount + rightCount, new char[leftCount + rightCount]);

			sw.WriteLine(result);
		}

		private void Generate(int currLeft, int currRight, int leftCount, int rightCount, int totalMax, char[] array)
		{
			if (currLeft + currRight == totalMax) {
				var contains = new int[7];
				for (var i = 0; i < array.Length; i++) {
					contains[array[i] - '0']++;
				}
				var isDifferent = contains.All(item => item <= 1);
				if (isDifferent) {
					var leftStr = new String(array, 0, leftCount);
					var rightStr = new String(array, leftCount, rightCount);
					var leftVal = String.IsNullOrEmpty(leftStr) ? 0L : Int64.Parse(leftStr);
					var rightVal = String.IsNullOrEmpty(rightStr) ? 0L : Int64.Parse(rightStr);
					var firstVal = String.IsNullOrEmpty(firstStr) ? 0L :Int64.Parse(firstStr);
					var secondVal = String.IsNullOrEmpty(secondStr) ? 0L : Int64.Parse(secondStr);
					if (leftVal <= firstVal && rightVal <= secondVal) {
						result++;
					}
				}
			}
			else {
				for (var i = 0; i < 7; i++) {
					array[currLeft + currRight] = (char) ('0' + i);
					if (currLeft < leftCount)
						Generate(currLeft + 1, currRight, leftCount, rightCount, totalMax, array);
					else
						Generate(currLeft, currRight + 1, leftCount, rightCount, totalMax, array);
				}
			}
		}

		private List<int> ToSevenBase(long n)
		{
			if (n == 0) {
				return new List<int> { 0 };
			}
			const int b = 7;
			var list = new List<int>();
			var curr = (int)n;
			while (curr > 0) {
				list.Add(curr % b);
				curr /= b;
			}

			return list;
		}
	}
}

internal class InputReader : IDisposable
{
	private bool isDispose;
	private readonly TextReader sr;

	public InputReader(TextReader stream)
	{
		sr = stream;
	}

	public void Dispose()
	{
		Dispose(true);
		GC.SuppressFinalize(this);
	}

	public string NextString()
	{
		var result = sr.ReadLine();
		return result;
	}

	public int NextInt32()
	{
		return Int32.Parse(NextString());
	}

	public long NextInt64()
	{
		return Int64.Parse(NextString());
	}

	public string[] NextSplitStrings()
	{
		return NextString()
			.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
	}

	public T[] ReadArray<T>(Func<string, CultureInfo, T> func)
	{
		return NextSplitStrings()
			.Select(s => func(s, CultureInfo.InvariantCulture))
			.ToArray();
	}

	public T[] ReadArrayFromString<T>(Func<string, CultureInfo, T> func, string str)
	{
		return
			str.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries)
				.Select(s => func(s, CultureInfo.InvariantCulture))
				.ToArray();
	}

	protected void Dispose(bool dispose)
	{
		if (!isDispose) {
			if (dispose)
				sr.Close();
			isDispose = true;
		}
	}

	~InputReader()
	{
		Dispose(false);
	}
}

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

namespace AlgoTraining.Codeforces.C_s
{
    public class FastScanner : StreamReader
    {
        private string[] _line;
        private int _iterator;

        public FastScanner(Stream stream) : base(stream)
        {
            _line = null;
            _iterator = 0;
        }
        public int NextInt()
        {
            if (_line == null || _iterator >= _line.Length)
            {
                _line = base.ReadLine().Split(' ');
                _iterator = 0;
            }
            if (_line.Count() == 0) throw new IndexOutOfRangeException("Input string is empty");
            return Convert.ToInt32(_line[_iterator++]);
        }
        public long NextLong()
        {
            if (_line == null || _iterator >= _line.Length)
            {
                _line = base.ReadLine().Split(' ');
                _iterator = 0;
            }
            if (_line.Count() == 0) throw new IndexOutOfRangeException("Input string is empty");
            return Convert.ToInt64(_line[_iterator++]);
        }
    }
    class AATask3
    {
        public static void Main(string[] args)
        {
            using (FastScanner fs = new FastScanner(new BufferedStream(Console.OpenStandardInput())))
            using (StreamWriter writer = new StreamWriter(new BufferedStream(Console.OpenStandardOutput())))
            {
                int n = fs.NextInt(), m = fs.NextInt();
                if (n > 823543 || m > 823543) writer.WriteLine(0);
                else
                {
                    List<string> hours = new List<string>(6000);
                    List<string> minutes = new List<string>(6000);
                    char[] nums = new char[] { '0', '1', '2', '3', '4', '5', '6' };
                    string maxHour = IntToStringFast(n - 1, nums);
                    string maxMinute = IntToStringFast(m - 1, nums);
                    if (maxHour.Length + maxMinute.Length > 7)
                    {
                        writer.WriteLine(0);
                        return;
                    }
                    for (int i = 0; i < n; i++)
                    {
                        StringBuilder sb = new StringBuilder(IntToStringFast(i, nums));
                        while (sb.Length < maxHour.Length) sb.Insert(0, 0);
                        string hour = sb.ToString();
                        if (IsUnique(hour))
                        {
                            hours.Add(hour);
                        }
                    }
                    for (int i = 0; i < m; i++)
                    {
                        StringBuilder sb = new StringBuilder(IntToStringFast(i, nums));
                        while (sb.Length < maxMinute.Length) sb.Insert(0, 0);
                        string minute = sb.ToString();
                        if (IsUnique(minute))
                        {
                            minutes.Add(minute);
                        }
                    }
                    int ans = 0;
                    foreach (string h in hours)
                    {
                        foreach (string min in minutes)
                        {
                            if (AreUnique(h, min))
                            {
                                ans++;
                            }
                        }
                    }
                    writer.WriteLine(ans);
                }
            }
        }

        private static bool AreUnique(string hour, string min)
        {
            bool[] count = new bool[7];
            for (int i = 0; i < hour.Length; i++)
            {
                count[hour[i] - '0'] = true;
            }
            for (int i = 0; i < min.Length; i++)
            {
                if (count[min[i] - '0']) return false;
            }
            return true;
        }

        private static bool IsUnique(string hour)
        {
            bool[] count = new bool[7];
            for (int i = 0; i < hour.Length; i++)
            {
                if (count[hour[i] - '0']) return false;
                else count[hour[i] - '0'] = true;
            }
            return true;
        }
        public static string IntToStringFast(int value, char[] baseChars)
        {
            // 32 is the worst cast buffer size for base 2 and int.MaxValue
            int i = 32;
            char[] buffer = new char[i];
            int targetBase = baseChars.Length;

            do
            {
                buffer[--i] = baseChars[value % targetBase];
                value = value / targetBase;
            }
            while (value > 0);

            char[] result = new char[32 - i];
            Array.Copy(buffer, i, result, 0, 32 - i);

            return new string(result);
        }
    }
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Security.AccessControl;
using System.Text;
using System.Threading.Tasks;

namespace olimpSolve
{
    class Program
    {
        static void Main(string[] args)
        {
            var p = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
            int n = p[0];
            int m = p[1];
            int t1 = (int)Math.Ceiling(Math.Log(n, 7));
            int t2 = (int) Math.Ceiling(Math.Log(m, 7));
            if (t1 == 0)
                t1 = 1;
            if (t2 == 0)
                t2 = 1;
            int result = 0;
            if (t1 + t2 <= 7)
            {
                var arr = new List<int[]>();
                Generate(arr, 0, new int[t1 + t2]);
                foreach (var item in arr)
                {
                    int p1 = ToDec(item, 0, t1);
                    int p2 = ToDec(item, t1, item.Length);
                    if (p1 < n && p2 < m)
                        result++;
                }
            }
            Console.WriteLine(result);
            Console.ReadLine();
        }

        private static int ToDec(int[] arr, int l, int r)
        {
            int k = 0;
            for (int i = l; i < r; i++)
            {
                k = k * 7 + arr[i];
            }
            return k;
        }

        private static void Generate(List<int[]>arr , int index, int[] was)
        {
            if (index == was.Length)
            {
                arr.Add(was.ToArray());
            }
            else
            {
                for (int i = 0; i < 7; i++)
                {
                    if (!was.Take(index).Contains(i))
                    {
                        was[index] = i;
                        Generate(arr, index + 1, was);
                    }
                }
            }
        }
    }
}

/*
 * TemplateCS
 * Copyright (C) 2014-2016 Markus Himmel
 * This file is distributed under the terms of the MIT license
 */

//#define CodeJam
#define CodeForces

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

namespace ProgrammingCompetitions
{
	class Program
	{

#region GCJ
#if CodeJam
		private static bool DEBUG = false;

		static void debug()
		{
		}

		static string solveCase(int num)
		{
			checked
			{
				return null;
			}
		}
#endif
#endregion

#region CodeForces
#if CodeForces
#if DEBUG
		static Queue<string> testInput = new Queue<string>(new string[]
		{
			"1 1",
		});
#endif

		static string Solve()
		{
			checked
			{
				int n, m;
				read(out n, out m);

				int h = 7;
				int nneed = 1;
				while (h < n)
				{
					nneed++;
					h *= 7;
				}
				h = 7;
				int mneed = 1;
				while (h < m)
				{
					mneed++;
					h *= 7;
				}
				if (mneed + nneed > 7)
					return "0";

				int res = 0;

				// at most 7^7
				for (int i = 0; i < n; i++)
				{
					for (int j = 0; j < m; j++)
					{
						HashSet<int> e = new HashSet<int>();
						bool o = false;
						int ii = i, jj = j;
						for (int nn = 0; nn < nneed; nn++)
						{
							if (!e.Add(ii % 7))
							{
								o = true;
								break;
							}
							ii /= 7;
						}
						if (o)
							continue;
						for (int mm = 0; mm < mneed; mm++)
						{
							if (!e.Add(jj % 7))
							{
								o = true;
								break;
							}
							jj /= 7;
						}
						if (!o)
						{
							res++;
						}
					}
				}
				return res.ToString();
			}
		}
#endif
#endregion

		// Everything after this comment is template code

		private static T read<T>()
		{
			return (T)Convert.ChangeType(read(), typeof(T));
		}

		private static T[] readMany<T>()
		{
			return readMany<T>(' ');
		}

		private static _[] readMany<_>(params char[] ___)
		{
			return read().Split(___).Select(__ => (_)Convert.ChangeType(__, typeof(_))).ToArray();
		}

		private static string[] readMany()
		{
			return readMany<string>();
		}

		private static T[][] readMany<T>(int n)
		{
			T[][] res = new T[n][];
			for (int i = 0; i < n; i++)
			{
				res[i] = readMany<T>();
			}
			return res;
		}

		private static T[][] readField<T>(int height, Func<char, T> map)
		{
			T[][] res = new T[height][];
			for (int _ = 0; _ < height; _++)
			{
				res[_] = read().Select(c => map(c)).ToArray();
			}
			return res;
		}

		private static char[][] readField(int height)
		{
			return readField(height, c => c);
		}

		private static T[][] readField<T>(int height, Dictionary<char, T> dic)
		{
			return readField(height, c => dic[c]);
		}

		private static void read<T1>(out T1 t1)
		{
			var vals = readMany();
			t1 = (T1)Convert.ChangeType(vals[0], typeof(T1));
		}

		private static void read<T1, T2>(out T1 t1, out T2 t2)
		{
			var vals = readMany();
			t1 = (T1)Convert.ChangeType(vals[0], typeof(T1));
			t2 = (T2)Convert.ChangeType(vals[1], typeof(T2));
		}

		private static void read<T1, T2, T3>(out T1 t1, out T2 t2, out T3 t3)
		{
			var vals = readMany();
			t1 = (T1)Convert.ChangeType(vals[0], typeof(T1));
			t2 = (T2)Convert.ChangeType(vals[1], typeof(T2));
			t3 = (T3)Convert.ChangeType(vals[2], typeof(T3));
		}

		private static void read<T1, T2, T3, T4>(out T1 t1, out T2 t2, out T3 t3, out T4 t4)
		{
			var vals = readMany();
			t1 = (T1)Convert.ChangeType(vals[0], typeof(T1));
			t2 = (T2)Convert.ChangeType(vals[1], typeof(T2));
			t3 = (T3)Convert.ChangeType(vals[2], typeof(T3));
			t4 = (T4)Convert.ChangeType(vals[3], typeof(T4));
		}

		private static void read<T1, T2, T3, T4, T5>(out T1 t1, out T2 t2, out T3 t3, out T4 t4, out T5 t5)
		{
			var vals = readMany();
			t1 = (T1)Convert.ChangeType(vals[0], typeof(T1));
			t2 = (T2)Convert.ChangeType(vals[1], typeof(T2));
			t3 = (T3)Convert.ChangeType(vals[2], typeof(T3));
			t4 = (T4)Convert.ChangeType(vals[3], typeof(T4));
			t5 = (T5)Convert.ChangeType(vals[4], typeof(T5));
		}

		static Func<T1, TResult> DP<T1, TResult>(Func<T1, Func<T1, TResult>, TResult> f)
		{
			var cache = new Dictionary<Tuple<T1>, TResult>();
			Func<T1, TResult> res = null;
			res = (t1) =>
			{
				var key = Tuple.Create(t1);
				if (!cache.ContainsKey(key))
					cache.Add(key, f(t1, res));
				return cache[key];
			};
			return res;
		}

		static Func<T1, T2, TResult> DP<T1, T2, TResult>(Func<T1, T2, Func<T1, T2, TResult>, TResult> f)
		{
			var cache = new Dictionary<Tuple<T1, T2>, TResult>();
			Func<T1, T2, TResult> res = null;
			res = (t1, t2) =>
			{
				var key = Tuple.Create(t1, t2);
				if (!cache.ContainsKey(key))
					cache.Add(key, f(t1, t2, res));
				return cache[key];
			};
			return res;
		}

		static Func<T1, T2, T3, TResult> DP<T1, T2, T3, TResult>(Func<T1, T2, T3, Func<T1, T2, T3, TResult>, TResult> f)
		{
			var cache = new Dictionary<Tuple<T1, T2, T3>, TResult>();
			Func<T1, T2, T3, TResult> res = null;
			res = (t1, t2, t3) =>
			{
				var key = Tuple.Create(t1, t2, t3);
				if (!cache.ContainsKey(key))
					cache.Add(key, f(t1, t2, t3, res));
				return cache[key];
			};
			return res;
		}

		static Func<T1, T2, T3, T4, TResult> DP<T1, T2, T3, T4, TResult>(Func<T1, T2, T3, T4, Func<T1, T2, T3, T4, TResult>, TResult> f)
		{
			var cache = new Dictionary<Tuple<T1, T2, T3, T4>, TResult>();
			Func<T1, T2, T3, T4, TResult> res = null;
			res = (t1, t2, t3, t4) =>
			{
				var key = Tuple.Create(t1, t2, t3, t4);
				if (!cache.ContainsKey(key))
					cache.Add(key, f(t1, t2, t3, t4, res));
				return cache[key];
			};
			return res;
		}

		static IEnumerable<T> single<T>(T it)
		{
			yield return it;
		}

		static IEnumerable<long> range(long first, long last, long step = 1)
		{
			for (long i = first; i <= last; i += step)
			{
				yield return i;
			}
		}

		static IEnumerable<int> range(int first, int last, int step = 1)
		{
			for (int i = first; i <= last; i+= step)
			{
				yield return i;
			}
		}

		static T id<T>(T a)
		{
			return a;
		}

		public static T[][] mkarr<T>(int x, int y)
		{
			T[][] res = new T[x][];
			for (int i = 0; i < x; i++)
			{
				res[i] = new T[y];
			}
			return res;
		}

		public static T[][][] mkarr<T>(int x, int y, int z)
		{
			T[][][] res = new T[x][][];
			for (int i = 0; i < x; i++)
			{
				res[i] = new T[y][];
				for (int j = 0; j < y; j++)
				{
					res[i][j] = new T[z];
				}
			}
			return res;
		}

		static bool[] tf = new[] { true, false };

#if CodeJam

		static void Main(string[] args)
		{
			if (DEBUG)
			{
				debug();
			}
			else
			{
				Initialize();
				SolveAll(solveCase);
			}
			Console.ReadKey();
		}

		private static StreamReader inf;
		private static StreamWriter outf;

		private delegate void o(string format, params object[] args);
		private static o Output;

		public static void Initialize()
		{
			Console.ForegroundColor = ConsoleColor.Yellow;
			Console.Write("File name: ");
			string name = Console.ReadLine();
			inf = new StreamReader($"D:\\Users\\marku\\Downloads\\{name}.in");
			outf = new StreamWriter($"D:\\Users\\marku\\Downloads\\{name}.out");
			Console.ForegroundColor = ConsoleColor.White;
			Output = highlightedPrint;
			Output += outf.WriteLine;
		}

		private static void highlightedPrint(string format, params object[] args)
		{
			ConsoleColor prev = Console.ForegroundColor;
			Console.ForegroundColor = ConsoleColor.Green;
			Console.WriteLine(format, args);
			Console.ForegroundColor = prev;
		}

		public static void SolveAll(Func<int, string> calc)
		{
			int cases = int.Parse(inf.ReadLine());
			for (int _ = 1; _ <= cases; _++)
			{
				Output($"Case #{_}: {calc(_)}");
			}
			inf.Close();
			outf.Close();
			Console.ForegroundColor = ConsoleColor.Cyan;
			Console.WriteLine("Eureka!");
		}

		private static string read()
		{
			return inf.ReadLine();
		}
#endif

#if CodeForces
		static void Main(string[] args)
		{
#if DEBUG
			var sw = new System.Diagnostics.Stopwatch();
			sw.Start();
#endif
			string s = Solve();
			if (!string.IsNullOrEmpty(s))
			{
				Console.WriteLine(s);
			}
#if DEBUG
			sw.Stop();
			Console.WriteLine(sw.Elapsed);
			Console.ReadKey();
#endif
		}

		private static string read()
		{
#if !DEBUG
			return Console.ReadLine();
#else
			return testInput.Dequeue();
#endif
		}
#endif
	}

	public static class ExtensionMethods
	{
		public static IEnumerable<TOut> Cartesian<T1, T2, TOut>(this IEnumerable<T1> first, IEnumerable<T2> second, Func<T1, T2, TOut> collector)
		{
			return first.SelectMany(f => second.Select(s => collector(f, s)));
		}

		public static IEnumerable<Tuple<T1, T2>> Cartesian<T1, T2>(this IEnumerable<T1> first, IEnumerable<T2> second)
		{
			return first.Cartesian(second, Tuple.Create);
		}

		public static IEnumerable<Tuple<T1, T2>> CartesianE<T1, T2>(this IEnumerable<T1> first, IEnumerable<T2> second)
		{
			// Calling CartesianE prevents selection of the wrong overload of Cartesian when you want a tuple of tuples to be returned
			return first.Cartesian(second);
		}

		public static IEnumerable<Tuple<T1, T2, T3>> Cartesian<T1, T2, T3>(this IEnumerable<Tuple<T1, T2>> first, IEnumerable<T3> second)
		{
			return first.Cartesian(second, (x, y) => Tuple.Create(x.Item1, x.Item2, y));
		}

		public static IEnumerable<Tuple<T1, T2, T3, T4>> Cartesian<T1, T2, T3, T4>(this IEnumerable<Tuple<T1, T2, T3>> first, IEnumerable<T4> second)
		{
			return first.Cartesian(second, (x, y) => Tuple.Create(x.Item1, x.Item2, x.Item3, y));
		}

		public static IEnumerable<Tuple<T1, T2, T3, T4, T5>> Cartesian<T1, T2, T3, T4, T5>(this IEnumerable<Tuple<T1, T2, T3, T4>> first, IEnumerable<T5> second)
		{
			return first.Cartesian(second, (x, y) => Tuple.Create(x.Item1, x.Item2, x.Item3, x.Item4, y));
		}

		public static IEnumerable<IEnumerable<T>> Cartesian<T>(this IEnumerable<IEnumerable<T>> source)
		{
			IEnumerable<IEnumerable<T>> res = source.First().Select(x => single(x));
			foreach (IEnumerable<T> next in source.Skip(1))
			{
				res = res.Cartesian(next, (sofar, n) => sofar.Concat(single(n)));
			}
			return res;
		}

		public static IEnumerable<IEnumerable<T>> Pow<T>(this IEnumerable<T> it, int num)
		{
			return Enumerable.Repeat(it, num).Cartesian();
		}

		public static IEnumerable<T> Demask<T>(this IEnumerable<Tuple<T, bool>> inp)
		{
			foreach (var pair in inp)
			{
				if (pair.Item2)
				{
					yield return pair.Item1;
				}
			}
		}

		public static IEnumerable<IEnumerable<IEnumerable<T>>> Partition<T>(this IEnumerable<T> source, int groups)
		{
			foreach (var part in Enumerable.Range(0, groups).Pow(source.Count()).Select(x => x.ToArray()))
			{
				yield return Enumerable.Range(0, groups).Select(x => source.Where((item, idx) => part[idx] == x));
			}
		}

		public static IEnumerable<IEnumerable<T>> Combinations<T>(this IEnumerable<T> it)
		{
			foreach (var conf in new[] { true, false }.Pow(it.Count()))
			{
				yield return it.Zip(conf, Tuple.Create).Demask();
			}
		}

		private static IEnumerable<T> single<T>(T it)
		{
			yield return it;
		}

		private static IEnumerable<T> ExceptSingle<T>(this IEnumerable<T> first, T it, IEqualityComparer<T> comp = null)
		{
			comp = comp ?? EqualityComparer<T>.Default;
			bool seen = false;
			foreach (T a in first)
			{
				if (!seen && comp.Equals(a, it))
				{
					seen = true;
				}
				else
				{
					yield return a;
				}
			}
		}

		public static IEnumerable<IEnumerable<T>> Permutations<T>(this IEnumerable<T> it)
		{
			if (it.Count() < 2)
			{
				yield return it;
				yield break;
			}

			foreach (T first in it)
			{
				foreach (IEnumerable<T> part in Permutations(it.ExceptSingle(first)))
				{
					yield return single(first).Concat(part);
				}
			}
		}

		public static T[][] Rho<T>(this IEnumerable<T> source, int x, int y)
		{
			T[][] res = Program.mkarr<T>(x, y);

			int i = 0, j = 0;

			while (true)
			{
				foreach (T item in source)
				{
					res[i][j] = item;
					j++;
					if (j == y)
					{
						j = 0;
						i++;
						if (i == x)
							break;
					}
				}
				if (i == x)
					break;
			}

			return res;
		}

		public static T[][][] Rho<T>(this IEnumerable<T> source, int x, int y, int z)
		{
			T[][][] res = Program.mkarr<T>(x, y, z);

			int i = 0, j = 0, k = 0;
			while (true)
			{
				foreach (T item in source)
				{
					res[i][j][k] = item;
					k++;
					if (k == z)
					{
						k = 0;
						j++;
						if (j == y)
						{
							j = 0;
							i++;
							if (i == x)
							{
								break;
							}
						}
					}
				}
				if (i == x)
					break;
			}

			return res;
		}
	}
}

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

class Program
{
    static void Main(string[] args)
    {
        var str = Console.ReadLine().Split(' ');
        var n = Convert.ToInt32(str[0]);
        var m = Convert.ToInt32(str[1]);
        if (n < m)
        {
            var t = n;
            n = m;
            m = t;
        }
        var nc = 0;
        var nn = n - 1;
        while (nn > 0)
        {
            ++nc;
            nn /= 7;
        }
        var mc = 0;
        var mm = m - 1;
        while (mm > 0)
        {
            ++mc;
            mm /= 7;
        }
        if (mc == 0)
            mc = 1;
        if (nc == 0)
            nc = 1;
        if (mc + nc > 7)
        {
            Console.WriteLine(0);
        }
        else
        {
            int mx = 1;
            int res = 0;
            var over = mc + nc;
            while (over > 0)
            {
                mx *= 7;
                over--;
            }

            var z = new int[7];
            for (int i = 0; i < mx; ++i)
            {
                for (int h = 0; h < 7; h++)
                    z[h] = 0;
                var j = i;
                var c = mc + nc;
                bool good = true;
                while (c > 0)
                {
                    if (z[j%7] > 0)
                    {
                        good = false;
                        break;
                    }
                    z[j%7]++;
                    j /= 7;
                    c--;
                }
                if (good)
                {
                    j = i;
                    c = mc;
                    int q = 1;
                    while (c > 0)
                    {
                        q *= 7;
                        j /= 7;
                        c--;
                    }
                    var nj = i - j*q;
                    if (j < n && nj < m)
                    {
                        res++;
                    }
                }
            }

            Console.WriteLine(res);
        }
    }
}

using System;
using System.IO;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;

class Program
{
    bool[] a = new bool[7];
    bool Check(int x, int v)
    {
        return x < v;
    }

    int GetCount(int k)
    {
        k--;
        int count = 0;
        for (;;)
        {
            count++;
            k /= 7;
            if (k == 0)
                return count;
        }
    }
    int n;
    int m;
    int countN;
    int countM;
    int res;

    //(0,0)
    void tutuFirst(int first, int countF)
    {
        if (countF == countN)
        {
            if (Check(first, n))
            {
                tutuSecond(0, 0);
            }
            return;
        }
        for (int j = 0; j < 7; j++)
        {
            if (a[j]) continue;
            a[j] = true;
            tutuFirst(first * 7 + j, countF + 1);
            a[j] = false;
        }
    }
    void tutuSecond(int second, int countS)
    {
        if (countS == countM)
        {
            if (Check(second, m))
            {
                res++;
            }
            return;
        }
        for (int j = 0; j < 7; j++)
        {
            if (a[j]) continue;
            a[j] = true;
            tutuSecond(second * 7 + j, countS + 1);
            a[j] = false;
        }
    }

    //////////////////////////////////////////////////
    void Solution()
    {
        n = ri;
        m = ri;

        countN = GetCount(n);
        countM = GetCount(m);
        var count = countM + countN;

        if (count > 7)
        {
            wln(0);
            return;
        }

        res = 0;
        tutuFirst(0, 0);
        wln(res);
    }
    //////////////////////////////////////////////////

    static void swap(ref object o1, ref object o2) { var o = o1; o1 = o2; o2 = o; }
    static void wln(object o = null) { Console.WriteLine(o); }
    static void wsp(object o) { Console.Write(o + " "); }
    static void wrt(object o) { Console.Write(o); }
    //Console.Write(string.Format(CultureInfo.InvariantCulture, "{0:F12}", o));

    static long gcd(long a, long b) { return (b != 0) ? gcd(b, a % b) : a; }
    static long lcm(long a, long b) { return a / gcd(a, b) * b; }

    int ri
    {
        get
        {
            _read(); while (_str[_ind] == ' ') ++_ind;
            int sign = 1; if (_str[_ind] == '-') { sign = -1; ++_ind; }
            int p = 0;
            while (_ind < _count && _str[_ind] != ' ') p = p * 10 + _str[_ind++] - '0';
            while (_ind < _count && _str[_ind] == ' ') ++_ind; return p * sign;
        }
    }
    long rl
    {
        get
        {
            _read(); while (_str[_ind] == ' ') ++_ind;
            int sign = 1; if (_str[_ind] == '-') { sign = -1; ++_ind; }
            long p = 0;
            while (_ind < _count && _str[_ind] != ' ') p = p * 10 + _str[_ind++] - '0';
            while (_ind < _count && _str[_ind] == ' ') ++_ind; return p * sign;
        }
    }
    double rd
    {
        get
        {
            _read(); while (_str[_ind] == ' ') ++_ind; int sign = 1; if (_str[_ind] == '-') { sign = -1; ++_ind; }
            long p = 0, q = 1; while (_ind < _count && _str[_ind] != ' ' && _str[_ind] != '.') p = p * 10 + _str[_ind++] - '0';
            if (_ind < _count && _str[_ind] == '.') { ++_ind; while (_ind < _count && _str[_ind] != ' ') { p = p * 10 + _str[_ind++] - '0'; q *= 10; } }
            while (_ind < _count && _str[_ind] == ' ') ++_ind; return (double)p / q * sign;
        }
    }
    string rs
    {
        get
        {
            _read(); while (_ind < _count && _str[_ind] == ' ') ++_ind;
            var tmp = _str.IndexOf(' ', _ind);
            if (tmp == -1) { _count = 0; _ind = 0; return _str.Substring(_ind); }
            var s = _str.Substring(_ind, tmp - _ind); _ind = tmp + 1;
            while (_ind < _count && _str[_ind] == ' ') ++_ind; return s;
        }
    }

    int[] ria(int n)
    {
        var res = new int[n];
        for (int k = 0; k < n;)
        {
            var s = Console.ReadLine(); var m = s.Length;
            for (int i = 0; i < m && k < n; ++i)
            {
                while (i < m && s[i] == ' ') ++i; if (i == m) break; int sign = 1; if (s[i] == '-') { sign = -1; ++i; }
                int p = 0; while (i < m && s[i] != ' ') p = p * 10 + s[i++] - '0'; res[k++] = p * sign;
            }
        }
        _count = 0; _ind = 0; return res;
    }
    long[] rla(int n)
    {
        var res = new long[n];
        for (int k = 0; k < n;)
        {
            var s = Console.ReadLine(); var m = s.Length;
            for (int i = 0; i < m && k < n; ++i)
            {
                while (i < m && s[i] == ' ') ++i; if (i == m) break; int sign = 1; if (s[i] == '-') { sign = -1; ++i; }
                long p = 0; while (i < m && s[i] != ' ') p = p * 10 + s[i++] - '0'; res[k++] = p * sign;
            }
        }
        _count = 0; _ind = 0; return res;
    }
    double[] rda(int n)
    {
        var res = new double[n];
        for (int k = 0; k < n;)
        {
            var s = Console.ReadLine(); var m = s.Length;
            for (int i = 0; i < m && k < n; ++i)
            {
                while (i < m && s[i] == ' ') ++i; if (i == m) break; int sign = 1; if (s[i] == '-') { sign = -1; ++i; }
                long p = 0, q = 1; while (i < m && s[i] != ' ' && s[i] != '.') p = p * 10 + s[i++] - '0';
                if (i < m && s[i] == '.') { ++i; while (i < m && s[i] != ' ') { p = p * 10 + s[i++] - '0'; q *= 10; } }
                res[k++] = (double)p / q * sign;
            }
        }
        _count = 0; _ind = 0; return res;
    }
    string[] rsa(int n) { var res = new string[n]; for (int k = 0; k < n; ++k) res[k] = Console.ReadLine(); _count = 0; _ind = 0; return res; }
    string _str = null; int _count = 0; int _ind = 0;
    void _read() { if (_ind == _count) { _str = Console.ReadLine(); _count = _str.Length; _ind = 0; } }
    static void Main() { new Program().Solution(); }
}

// using a C# contest template, relevant code is at the bottom in the Run() function

using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Text;

class ProblemA {
    static string inputFileName = "../../input.txt";
    static StreamReader fileReader;
    static string[] inputTokens;
    static int curInputTokenIndex;
    static bool isLocal = Type.GetType("HaitaoLocal") != null;
    static string NextToken() {
        string ret = "";
        while (ret == "") {
            if (inputTokens == null || curInputTokenIndex >= inputTokens.Length) {
                string line;
                if (isLocal) {
                    line = fileReader.ReadLine();
                    if (line == null) {
                        throw new Exception("Error: out of input tokens!");
                    }
                } else {
                    line = Console.ReadLine();
                }
                inputTokens = line.Split();
                curInputTokenIndex = 0;
            }
            ret = inputTokens[curInputTokenIndex++];
        }
        return ret;
    }
    static int ri { get { return RI(); } }
    static string rs { get { return RS(); } }
    static long rl { get { return RL(); } }
    static double rd { get { return RD(); } }
    static int RI() {
        return Int32.Parse(NextToken());
    }
    static string RS() {
        return NextToken();
    }
    static long RL() {
        return Int64.Parse(NextToken());
    }
    static double RD() {
        return Double.Parse(NextToken());
    }
    static int[] RIA(int length) {
        int[] ret = new int[length];
        for (int i = 0; i < length; i++) {
            ret[i] = RI();
        }
        return ret;
    }
    static string[] RSA(int length) {
        string[] ret = new string[length];
        for (int i = 0; i < length; i++) {
            ret[i] = RS();
        }
        return ret;
    }
    static long[] RLA(int length) {
        long[] ret = new long[length];
        for (int i = 0; i < length; i++) {
            ret[i] = RL();
        }
        return ret;
    }
    static double[] RDA(int length) {
        double[] ret = new double[length];
        for (int i = 0; i < length; i++) {
            ret[i] = RD();
        }
        return ret;
    }
    static StringBuilder outputBuilder;
    static CultureInfo outputCulture = new CultureInfo("en-US");
    static void Out(object obj) {
        Type type = obj.GetType();
        string str = obj.ToString();
        if (type == typeof(double) || type == typeof(float)) {
            str = ((double)obj).ToString(outputCulture);
        }
        outputBuilder.Append(str + " ");
    }
    static void Outl() {
        Outl("");
    }
    static void Outl(object obj) {
        Out(obj);
        outputBuilder.Append("\n");
    }
    static void Flush() {
        if (isLocal) {
            ConsoleColor t = Console.ForegroundColor;
            Console.ForegroundColor = ConsoleColor.Green;
            Console.WriteLine();
            Console.WriteLine(outputBuilder.ToString());
            Console.ForegroundColor = t;
        } else {
            Console.WriteLine(outputBuilder.ToString());
        }
        outputBuilder = new StringBuilder();
    }
    static void Log(string label, object obj) {
        if (!isLocal) return;

        ConsoleColor t = Console.ForegroundColor;
        Console.ForegroundColor = ConsoleColor.Gray;
        Console.Write(label + ": ");
        Console.ForegroundColor = t;
        Log(obj);
    }
    static void Log(object obj) {
        if (!isLocal) return;

        ConsoleColor t = Console.ForegroundColor;
        Console.ForegroundColor = ConsoleColor.White;
        Console.WriteLine(ToStringRecursive(obj));
        Console.ForegroundColor = t;
    }
    static string ToStringRecursive(object obj) {
        StringBuilder sb = new StringBuilder();
        if (!(obj is string) && (obj is System.Collections.IEnumerable)) {
            System.Collections.IEnumerable en = obj as System.Collections.IEnumerable;
            sb.Append("{");
            bool first = true;
            foreach (object el in en) {
                if (!first) sb.Append(", ");
                sb.Append(ToStringRecursive(el));
                first = false;
            }
            sb.Append("}");
            return sb.ToString();
        }
        return obj.ToString();
    }

    public static void Main(string[] args) {
        long startTick = 0;
        if (isLocal) {
            startTick = Environment.TickCount;
            fileReader = new StreamReader(inputFileName);
        }

        outputBuilder = new StringBuilder();
        Run();
        if (isLocal) {
            ConsoleColor t = Console.ForegroundColor;
            Console.ForegroundColor = ConsoleColor.Green;
            Console.WriteLine();
            Console.WriteLine(outputBuilder.ToString());
            Console.WriteLine();
            Console.ForegroundColor = t;
        } else {
            Console.WriteLine(outputBuilder.ToString());
        }

        if (isLocal) {
            long runTime = Environment.TickCount - startTick;
            if (runTime > 32) {
                Log("time", runTime);
                Log("");
            }
        }
    }

    static void Run() {
        long n = rl;
        long m = rl;
        int nd = 0;
        long tn = n-1;
        if (tn == 0) nd = 1;
        while (tn > 0) {
            tn /= 7;
            nd++;
        }
        int md = 0;
        long tm = m-1;
        if (tm == 0) md = 1;
        while (tm > 0) {
            tm /= 7;
            md++;
        }
        if (nd + md > 7) Outl(0);
        else {
            long ans = 0;
            for (int a = 0; a < n; a++) {
                for (int b = 0; b < m; b++) {
                    bool[] x = new bool[7];
                    List<int> l = new List<int>();
                    int ta = a;
                    while (ta > 0) {
                        l.Add(ta % 7);
                        ta /= 7;
                    }
                    int tb = b;
                    while (tb > 0) {
                        l.Add(tb % 7);
                        tb /= 7;
                    }
                    if (l.Count < nd + md) {
                        l.Add(0);
                    }
                    if (l.Count < nd + md) {
                        continue;
                    }
                    bool flag = true;
                    foreach (int i in l) {
                        if (x[i]) {
                            flag = false; break;
                        }
                        x[i] = true;
                    }
                    if(flag) {
                        ans++;
                    }
                }
            }
            Outl(ans);
        }

    }
}

using System;
using System.Collections.Generic;
using System.IO;
using System.Text;

namespace Robbers__watch
{
    internal class Program
    {
        private static readonly StreamReader reader = new StreamReader(Console.OpenStandardInput(1024*10), Encoding.ASCII, false, 1024*10);
        private static readonly StreamWriter writer = new StreamWriter(Console.OpenStandardOutput(1024*10), Encoding.ASCII, 1024*10);

        private static void Main(string[] args)
        {
            int n = Next();
            int m = Next();

            int cn = Digits(n-1);
            int cm = Digits(m-1);

            var p = new[] {0, 1, 2, 3, 4, 5, 6};
            int count = 0;
            var h = new HashSet<long>();

            if (cn + cm <= p.Length)
            {
                do
                {
                    int i = 0;
                    long nn = 0, mm = 0;
                    for (int j = 0; j < cn; j++)
                    {
                        nn = nn*7 + p[i];
                        i++;
                    }
                    for (int j = 0; j < cm; j++)
                    {
                        mm = mm*7 + p[i];
                        i++;
                    }
                    if (nn < n && mm < m)
                    {
                        long key = (nn << 32) + mm;
                        if (h.Add(key))
                            count++;
                    }
                } while (NextPermutation(p));
            }

            writer.WriteLine(count);
            writer.Flush();
        }

        private static int Digits(int n)
        {
            if (n <= 0)
                return 1;
            int count = 0;
            while (n > 0)
            {
                n /= 7;
                count++;
            }
            return count;
        }

        private static bool NextPermutation(int[] nn)
        {
            if (nn.Length <= 1) return false;
            int i = nn.Length - 1;
            int last = nn.Length;

            while (true)
            {
                int i1 = i;
                if (nn[--i] < nn[i1])
                {
                    int i2 = last;
                    while (!(nn[i] < nn[--i2]))
                    {
                        ;
                    }
                    int c = nn[i];
                    nn[i] = nn[i2];
                    nn[i2] = c;

                    Reverse(nn, i1, last);
                    return true;
                }
                if (i == 0)
                {
                    Reverse(nn, 0, last);
                    return false;
                }
            }
        }

        private static void Reverse(int[] nn, int first, int last)
        {
            while ((first != last) && (first != --last))
            {
                int c = nn[first];
                nn[first] = nn[last];
                nn[last] = c;
                first++;
            }
        }

        private static int Next()
        {
            int c;
            int res = 0;
            do
            {
                c = reader.Read();
                if (c == -1)
                    return res;
            } while (c < '0' || c > '9');
            res = c - '0';
            while (true)
            {
                c = reader.Read();
                if (c < '0' || c > '9')
                    return res;
                res *= 10;
                res += c - '0';
            }
        }
    }
}

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

// (づ°ω°)づﾐe★゜・。。・゜゜・。。・゜☆゜・。。・゜゜・。。・゜
public class Solver
{
    List<int> Fun(int x)
    {
        var ret = new List<int>();
        if (x == 0)
        {
            ret.Add(0);
            return ret;
        }
        while (x > 0)
        {
            ret.Add(x % 7);
            x /= 7;
        }
        ret.Reverse();
        return ret;
    }

    public void Solve()
    {
        int n = ReadInt();
        int m = ReadInt();

        var dp = new int[1 << 7, 2];
        dp[0, 0] = 1;
        foreach (int x in Fun(n - 1))
        {
            var ndp = new int[1 << 7, 2];
            for (int i = 0; i < 1 << 7; i++)
                for (int j = 0; j < 2; j++)
                    for (int k = 0; k < 7; k++)
                        if ((i >> k & 1) == 0)
                        {
                            if (j == 0 && k > x)
                                continue;
                            int nj = j;
                            if (k < x)
                                nj = 1;
                            ndp[i | 1 << k, nj] += dp[i, j];
                        }
            dp = ndp;
        }

        for (int i = 0; i < 1 << 7; i++)
        {
            dp[i, 0] += dp[i, 1];
            dp[i, 1] = 0;
        }

        foreach (int x in Fun(m - 1))
        {
            var ndp = new int[1 << 7, 2];
            for (int i = 0; i < 1 << 7; i++)
                for (int j = 0; j < 2; j++)
                    for (int k = 0; k < 7; k++)
                        if ((i >> k & 1) == 0)
                        {
                            if (j == 0 && k > x)
                                continue;
                            int nj = j;
                            if (k < x)
                                nj = 1;
                            ndp[i | 1 << k, nj] += dp[i, j];
                        }
            dp = ndp;
        }

        int ans = 0;
        for (int i = 0; i < 1 << 7; i++)
            for (int j = 0; j < 2; j++)
                ans += dp[i, j];

        Write(ans);
    }

    #region Main

    protected static TextReader reader;
    protected static TextWriter writer;
    static void Main()
    {
#if DEBUG
        reader = new StreamReader("..\\..\\input.txt");
        //reader = new StreamReader(Console.OpenStandardInput());
        writer = Console.Out;
        //writer = new StreamWriter("..\\..\\output.txt");
#else
        reader = new StreamReader(Console.OpenStandardInput());
        writer = new StreamWriter(Console.OpenStandardOutput(),Encoding.ASCII);
        //reader = new StreamReader("input.txt");
        //writer = new StreamWriter("output.txt");
#endif
        try
        {
            new Solver().Solve();
            //var thread = new Thread(new Solver().Solve, 1024 * 1024 * 128);
            //thread.Start();
            //thread.Join();
        }
        catch (Exception ex)
        {
#if DEBUG
            Console.WriteLine(ex);
#else
            throw;
#endif
        }
        reader.Close();
        writer.Close();
    }

    #endregion

    #region Read / Write
    private static Queue<string> currentLineTokens = new Queue<string>();
    private static string[] ReadAndSplitLine() { return reader.ReadLine().Split(new[] { ' ', '\t', }, StringSplitOptions.RemoveEmptyEntries); }
    public static string ReadToken() { while (currentLineTokens.Count == 0)currentLineTokens = new Queue<string>(ReadAndSplitLine()); return currentLineTokens.Dequeue(); }
    public static int ReadInt() { return int.Parse(ReadToken()); }
    public static long ReadLong() { return long.Parse(ReadToken()); }
    public static double ReadDouble() { return double.Parse(ReadToken(), CultureInfo.InvariantCulture); }
    public static int[] ReadIntArray() { return ReadAndSplitLine().Select(int.Parse).ToArray(); }
    public static long[] ReadLongArray() { return ReadAndSplitLine().Select(long.Parse).ToArray(); }
    public static double[] ReadDoubleArray() { return ReadAndSplitLine().Select(s => double.Parse(s, CultureInfo.InvariantCulture)).ToArray(); }
    public static int[][] ReadIntMatrix(int numberOfRows) { int[][] matrix = new int[numberOfRows][]; for (int i = 0; i < numberOfRows; i++)matrix[i] = ReadIntArray(); return matrix; }
    public static int[][] ReadAndTransposeIntMatrix(int numberOfRows)
    {
        int[][] matrix = ReadIntMatrix(numberOfRows); int[][] ret = new int[matrix[0].Length][];
        for (int i = 0; i < ret.Length; i++) { ret[i] = new int[numberOfRows]; for (int j = 0; j < numberOfRows; j++)ret[i][j] = matrix[j][i]; } return ret;
    }
    public static string[] ReadLines(int quantity) { string[] lines = new string[quantity]; for (int i = 0; i < quantity; i++)lines[i] = reader.ReadLine().Trim(); return lines; }
    public static void WriteArray<T>(IEnumerable<T> array) { writer.WriteLine(string.Join(" ", array)); }
    public static void Write(params object[] array) { WriteArray(array); }
    public static void WriteLines<T>(IEnumerable<T> array) { foreach (var a in array)writer.WriteLine(a); }
    private class SDictionary<TKey, TValue> : Dictionary<TKey, TValue>
    {
        public new TValue this[TKey key]
        {
            get { return ContainsKey(key) ? base[key] : default(TValue); }
            set { base[key] = value; }
        }
    }
    private static T[] Init<T>(int size) where T : new() { var ret = new T[size]; for (int i = 0; i < size; i++)ret[i] = new T(); return ret; }
    #endregion
}

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

namespace TaskC
{
    class Program
    {
        static void Main(string[] args)
        {
            new Solver().Solve().OutputResult();
        }

        private class ExtendedReader : StreamReader
        {
            private static readonly char Separator = ' ';

            public ExtendedReader(Stream stream) : base(stream) { }
            public ExtendedReader(Stream stream, bool detectEncodingFromByteOrderMarks) : base(stream, detectEncodingFromByteOrderMarks) { }
            public ExtendedReader(Stream stream, Encoding encoding) : base(stream, encoding) { }
            public ExtendedReader(Stream stream, Encoding encoding, bool detectEncodingFromByteOrderMarks) : base(stream, encoding, detectEncodingFromByteOrderMarks) { }
            public ExtendedReader(Stream stream, Encoding encoding, bool detectEncodingFromByteOrderMarks, int bufferSize) : base(stream, encoding, detectEncodingFromByteOrderMarks, bufferSize) { }
            public ExtendedReader(Stream stream, Encoding encoding, bool detectEncodingFromByteOrderMarks, int bufferSize, bool leaveOpen) : base(stream, encoding, detectEncodingFromByteOrderMarks, bufferSize, leaveOpen) { }
            public ExtendedReader(string path) : base(path) { }
            public ExtendedReader(string path, bool detectEncodingFromByteOrderMarks) : base(path, detectEncodingFromByteOrderMarks) { }
            public ExtendedReader(string path, Encoding encoding) : base(path, encoding) { }
            public ExtendedReader(string path, Encoding encoding, bool detectEncodingFromByteOrderMarks) : base(path, encoding, detectEncodingFromByteOrderMarks) { }
            public ExtendedReader(string path, Encoding encoding, bool detectEncodingFromByteOrderMarks, int bufferSize) : base(path, encoding, detectEncodingFromByteOrderMarks, bufferSize) { }

            public char ReadChar()
            {
                return (char)this.Read();
            }

            public double ReadDoubleFromArray()
            {
                StringBuilder sb = new StringBuilder();
                char ch = this.ReadChar();
                while (ch != Separator && ch != '\n')
                {
                    sb.Append(ch);
                    ch = this.ReadChar();
                }
                return Convert.ToDouble(sb.ToString());
            }

            public int ReadInt()
            {
                return int.Parse(this.ReadLine());
            }

            public Int64 ReadInt64()
            {
                return Int64.Parse(this.ReadLine());
            }

            public int[] ReadIntArray()
            {
                return this.ReadLine().Split(' ').Select(int.Parse).ToArray();
            }

            public char[] ReadCharArray()
            {
                return this.ReadLine().ToCharArray();
            }

            public string ReadString()
            {
                return this.ReadLine();
            }

            public Int64[] ReadInt64Array()
            {
                return this.ReadLine().Split(Separator).Select(Int64.Parse).ToArray();
            }

            public Double[] ReadDoubleArray()
            {
                return this.ReadLine().Split(Separator).Select(Double.Parse).ToArray();
            }
        }

        private abstract class SolverBase
        {
            protected readonly ExtendedReader _reader;
            protected readonly TextWriter _writer;

            protected SolverBase()
            {
#if DEBUG
                _reader = new ExtendedReader(@"input.txt");
                //_writer = new StreamWriter(@"output.txt");
                _writer = new StreamWriter(Console.OpenStandardOutput());
#else
                _reader = new ExtendedReader(Console.OpenStandardInput());
                _writer = new StreamWriter(Console.OpenStandardOutput());
#endif
            }

            public abstract Solver Solve();

            public abstract void OutputResult();
        }

        private class Solver : SolverBase
        {
            private long result = 0;

            public override Solver Solve()
            {
                // link to task: http://codeforces.com/problemset/problem/681/C

                var input = _reader.ReadIntArray();
                var n = input[0];
                var m = input[1];
                var maxN = n / 7 + 1;
                var maxM = m / 7 + 1;
                var numbers = new HashSet<int>();

                if (Math.Max(n, m) > Math.Pow(7, 7))
                {
                    return this;
                }

                for (int i = 0; i < n; i++)
                {
                    for (int j = 0; j < m; j++)
                    {
                        if (i == j) continue;
                        numbers.Clear();
                        if (ToSeven(i, maxN, numbers) && ToSeven(j, maxM, numbers))
                        {
                            result++;
                        }
                    }
                }

                return this;
            }

            private bool ToSeven(int val, int max, HashSet<int> nums)
            {
                for (int i = max - 1; i >= 0; i--)
                {
                    var value = val % 7;
                    if (nums.Contains(value)) return false;
                    val /= 7;
                    nums.Add(value);
                }

                return true;
            }

            public override void OutputResult()
            {
                string answer = result.ToString();

                _writer.WriteLine(answer);
                _writer.Dispose();
            }
        }
    }
}

using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;

namespace Codeforces
{
    internal class Template
    {
        private void Solve()
        {
            var n = cin.NextInt();
            var m = cin.NextInt();

            var maxN = IntToString(n - 1);
            var maxM = IntToString(m - 1);

            var length = maxN.Length + maxM.Length;
            if (length > 7)
            {
                Console.WriteLine(0);
                return;
            }

            var mm = long.Parse(maxM);

            var count = 0;
            var chars = new List<char>();
            for (var i = 0; i < n; i++)
            {
                var hasZero = false;

                var num = IntToString(i);
                if (num.Length < maxN.Length)
                {
                    if (maxN.Length - num.Length == 1)
                    {
                        if (!num.Contains('0'))
                        {
                            hasZero = true;
                        }
                        else
                        {
                            continue;
                        }
                    }
                    else
                    {
                        continue;
                    }
                }

                chars.Clear();
                if (!hasZero && !num.Contains('0'))
                {
                    chars.Add('0');
                }

                for (var c = '1'; c <= '6'; c++)
                {
                    if (!num.Contains(c))
                    {
                        chars.Add(c);
                    }
                }

                var unique = new HashSet<string>();
                do
                {
                    var str = new string(chars.ToArray()).Substring(0, maxM.Length);
                    if (!unique.Contains(str))
                    {
                        unique.Add(str);
                        var value = long.Parse(str);
                        if (value <= mm)
                        {
                            count++;
                        }
                    }
                } while (NextPermutation(chars));
            }

            Console.WriteLine(count);

        }

        private static readonly char[] baseChars = new[] {'0', '1', '2', '3', '4', '5', '6'};

        public static string IntToString(int value)
        {
            string result = string.Empty;
            int targetBase = baseChars.Length;

            do
            {
                result = baseChars[value % targetBase] + result;
                value = value / targetBase;
            }
            while (value > 0);

            return result;
        }

        public static bool NextPermutation<T>(IList<T> items) where T : IComparable
        {
            var i = -1;
            for (var x = items.Count - 2; x >= 0; x--)
            {
                if (items[x].CompareTo(items[x + 1]) < 0)
                {
                    i = x;
                    break;
                }
            }

            if (i == -1)
            {
                return false;
            }
            var j = 0;
            for (var x = items.Count - 1; x > i; x--)
            {
                if (items[x].CompareTo(items[i]) > 0)
                {
                    j = x;
                    break;
                }
            }
            var temp = items[i];
            items[i] = items[j];
            items[j] = temp;
            //Array.Reverse(items, i + 1, items.Count - (i + 1));
            var index = i + 1;
            var endIndex = index + items.Count - (i + 1) - 1;
            while (index < endIndex)
            {
                temp = items[index];
                items[index] = items[endIndex];
                items[endIndex] = temp;
                index++;
                endIndex--;
            }
            return true;
        }

        private static readonly Scanner cin = new Scanner();

        private static void Main()
        {
#if DEBUG
            var inputText = File.ReadAllText(@"..\..\input.txt");
            var testCases = inputText.Split(new[] { "input" }, StringSplitOptions.RemoveEmptyEntries);
            var consoleOut = Console.Out;
            for (var i = 0; i < testCases.Length; i++)
            {
                var parts = testCases[i].Split(new[] { "output" }, StringSplitOptions.RemoveEmptyEntries);
                Console.SetIn(new StringReader(parts[0].Trim()));
                var stringWriter = new StringWriter();
                Console.SetOut(stringWriter);
                var sw = Stopwatch.StartNew();
                new Template().Solve();
                sw.Stop();
                var output = stringWriter.ToString();

                Console.SetOut(consoleOut);
                var color = ConsoleColor.Green;
                var status = "Passed";
                if (parts[1].Trim() != output.Trim())
                {
                    color = ConsoleColor.Red;
                    status = "Failed";
                }
                Console.ForegroundColor = color;
                Console.WriteLine("Test {0} {1} in {2}ms", i + 1, status, sw.ElapsedMilliseconds);
            }
            Console.ReadLine();
            Console.ReadKey();
#else
			new Template().Solve();
			Console.ReadLine();
#endif
        }
    }

    internal class Scanner
    {
        private string[] s = new string[0];
        private int i;
        private readonly char[] cs = { ' ' };

        public string NextString()
        {
            if (i < s.Length) return s[i++];
            var line = Console.ReadLine() ?? string.Empty;
            s = line.Split(cs, StringSplitOptions.RemoveEmptyEntries);
            i = 1;
            return s.First();
        }

        public double NextDouble()
        {
            return double.Parse(NextString());
        }

        public int NextInt()
        {
            return int.Parse(NextString());
        }

        public long NextLong()
        {
            return long.Parse(NextString());
        }
    }
}

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

internal class Program
{
    public static int GetMaxDigitsOf7CC(int n)
    {
        int ret = 0;
        if (n == 0)
            return 1;
        while (n != 0)
        {
            ret++;
            n /= 7;
        }
        return ret;
    }

    private static void Main(string[] args)
    {
        int ans = 0;
        var inp = (Console.ReadLine()).Split(' ').Select(int.Parse).ToArray();
        var h = inp[0];
        var m = inp[1];
        var hr = GetMaxDigitsOf7CC(h);
        var mr = GetMaxDigitsOf7CC(m);
        if (hr + mr > 7)
            Console.WriteLine("0");
        else
        {
            for (int i = 0; i < h; i++)
            {
                for (int j = 0; j < m; j++)
                {
                    int[] mas = new int[7];
                    bool is_ok = true;
                    //-----------h
                    int tmp = i;
                    for (int z1 = 0; z1 < hr; z1++)
                    {
                        int ost = tmp % 7;
                        mas[ost]++;
                        if (mas[ost] > 1)
                        {
                            is_ok = false;
                            break;
                        }
                        tmp /= 7;
                    }
                    //---------m
                    tmp = j;
                    for (int z2 = 0; z2 < mr; z2++)
                    {
                        int ost = tmp % 7;
                        mas[ost]++;
                        if (mas[ost] > 1)
                        {
                            is_ok = false;
                            break;
                        }
                        tmp /= 7;
                    }
                    if (is_ok == true)
                    {
                        //Console.WriteLine("{0} {1}", i, j);
                        ans++;
                    }
                }
            }
            Console.WriteLine("{0}", ans);
        }
    }
}

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

namespace _686C
{
    class Program
    {
        static int[] powers7 = new[] { 7, 49, 343, 2401, 16807, 117649, 823543, 5764801, 40353607, 282475249 };

        static void Main(string[] args)
        {
            string[] input = Console.ReadLine().Split(' ');
            int n = int.Parse(input[0]), m = int.Parse(input[1]);
            long answer = 0;
            int firstDigits = 0, secondDigits = 0;
            for (var a = 7; a < n; a *= 7)
                firstDigits += 1;
            for (var b = 7; b < m; b *= 7)
                secondDigits += 1;

            if (firstDigits + secondDigits <= 7)
            {
                for (int i = 0; i < n; i++)
                {
                    for (int j = 0; j < m; j++)
                    {
                        int[] used = new int[7];
                        for (int a = i, k = 0; k != firstDigits; a /= 7, k++)
                            used[a % 7]++;
                        for (int b = j, k = 0; k != secondDigits; b /= 7, k++)
                            used[b % 7]++;

                        if (used.Max() <= 1) answer++;
                    }
                }
            }

            Console.WriteLine(answer);
            //Console.ReadLine();
        }
    }
}

using System;
using System.Globalization;
using System.IO;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;
using System.Threading;

namespace Codeforces
{
    class Program : ProgramBase
    {
        private const long commonMod = 1000000007;

        static void Main(string[] args)
        {
            var p = new Program();
            var x = p.Get();
            p.Out(x);
        }

        object Get()
        {
            checked
            {
                //FileName = "input";
                var n = ReadLongToken();
                var m = ReadLongToken();
                var nlog = logbase7(n);
                var mlog = logbase7(m);
                if (nlog + mlog > 7)
                    return 0;
                var log = nlog + mlog;

                var result = 0;

                var a = new int[7] { 0, 1, 2, 3, 4, 5, 6 };
                int[] prev = new int[7];
                do
                {
                    if (prev != null)
                    {
                        var fl = true;
                        for (int i = 0; i < log; i++)
                        {
                            if (a[i] != prev[i])
                            {
                                fl = false;
                                break;
                            }
                        }
                        if (fl)
                        {
                            continue;
                        }
                    }
                    var v = 0;
                    var pow = 1;
                    for (int i = 0; i < nlog; i++)
                    {
                        v += a[i] * pow;
                        pow *= 7;
                    }
                    if (v >= n)
                    {
                        Array.Copy(a, prev, 7);
                        continue;
                    }

                    pow = 1;
                    v = 0;
                    for (int i = 0; i < mlog; i++)
                    {
                        v += a[nlog + i] * pow;
                        pow *= 7;
                    }
                    if (v >= m)
                    {
                        Array.Copy(a, prev, 7);
                        continue;
                    }
                    result++;
                    Array.Copy(a, prev, 7);
                } while (NextPermutation(a));
                return result;
            }

        }
        private static bool NextPermutation(int[] numList)
        {
            /*
             Knuths
             1. Find the largest index j such that a[j] < a[j + 1]. If no such index exists, the permutation is the last permutation.
             2. Find the largest index l such that a[j] < a[l]. Since j + 1 is such an index, l is well defined and satisfies j < l.
             3. Swap a[j] with a[l].
             4. Reverse the sequence from a[j + 1] up to and including the final element a[n].

             */
            var largestIndex = -1;
            for (var i = numList.Length - 2; i >= 0; i--)
            {
                if (numList[i] < numList[i + 1])
                {
                    largestIndex = i;
                    break;
                }
            }

            if (largestIndex < 0) return false;

            var largestIndex2 = -1;
            for (var i = numList.Length - 1; i >= 0; i--)
            {
                if (numList[largestIndex] < numList[i])
                {
                    largestIndex2 = i;
                    break;
                }
            }

            var tmp = numList[largestIndex];
            numList[largestIndex] = numList[largestIndex2];
            numList[largestIndex2] = tmp;

            for (int i = largestIndex + 1, j = numList.Length - 1; i < j; i++, j--)
            {
                tmp = numList[i];
                numList[i] = numList[j];
                numList[j] = tmp;
            }

            return true;
        }

        public int logbase7(long v)
        {
            var res = 0;
            v = v - 1;
            while(v > 0)
            {
                v /= 7;
                res++;
            }
            return res;
        }

        public static class Struct
        {
            public static Pair<T1, T2> Create<T1,T2>(T1 item1, T2 item2)
            {
                return new Pair<T1, T2> { Item1 = item1, Item2 = item2 };
            }
        }

        public struct Pair<T1, T2>
        {
            public T1 Item1 { get; set; }
            public T2 Item2 { get; set; }
        }

        class Automata
        {
            bool[] terminals;
            public int sigma;
            public int len;
            public int[,] jumps;

            public void Create()
            {
                var a = ReadInts();
                len = a[0];
                sigma = a[2];
                var ts = ReadInts();
                terminals = new bool[len];
                for (int i = 0; i < ts.Length; i++)
                    terminals[ts[i]] = true;
                jumps = new int[len, sigma];
                for (int i = 0; i < len * sigma; i++)
                {
                    var b = Console.ReadLine().Split(' ');
                    jumps[Convert.ToInt32(b[0]), b[1][0] - 'a'] = Convert.ToInt32(b[2]);
                }
            }
            protected int[] ReadInts()
            {
                return Console.ReadLine().Split(' ').Select(x => Convert.ToInt32(x)).ToArray();
            }

            public bool IsTerminal(int s)
            {
                return terminals[s];
            }
        }
    }

    abstract class ProgramBase
    {
        bool? prod = null;
        StreamReader f;
        Queue<string> tokens;
        protected string FileName { private get; set; }

        protected string Read()
        {
            if (f == null)
                f = string.IsNullOrEmpty(FileName)
                    ? new StreamReader(Console.OpenStandardInput())
                    : new StreamReader((GetProd() ? "" : "c:\\dev\\") + FileName);
            return f.ReadLine();
        }

        protected int ReadInt()
        {
            return int.Parse(Read());
        }

        protected int ReadIntToken()
        {
            if (tokens == null || tokens.Count == 0)
                tokens = new Queue<string>(Read().Split(' '));
            return int.Parse(tokens.Dequeue());
        }

        protected int[] ReadInts()
        {
            var tokens = Read().Split(' ');
            var result = new int[tokens.Length];
            for (int i = 0; i < tokens.Length; i++)
                result[i] = int.Parse(tokens[i]);
            return result;
        }

        protected long ReadLongToken()
        {
            if (tokens == null || tokens.Count == 0)
                tokens = new Queue<string>(Read().Split(' '));
            return long.Parse(tokens.Dequeue());
        }

        protected long ReadLong()
        {
            return Convert.ToInt64(Read());
        }

        protected long[] ReadLongs()
        {
            var tokens = Read().Split(' ');
            var result = new long[tokens.Length];
            for (int i = 0; i < tokens.Length; i++)
                result[i] = long.Parse(tokens[i]);
            return result;
        }

        public void Out(object r)
        {
            if (string.IsNullOrEmpty(FileName))
                Console.WriteLine(r);
            else if (GetProd())
                File.WriteAllText(FileName, r.ToString());
            else
                Console.WriteLine(r);
        }

        private bool GetProd()
        {

            if (!prod.HasValue)
                try
                {
                    prod = Environment.MachineName != "RENADEEN-W7";
                }
                catch (Exception)
                {
                    prod = true;
                }
            return prod.Value;
        }
    }

    public static class Huj
    {
        public static T MinBy<T>(this IEnumerable<T> source, Func<T, double> func) where T : class
        {
            T result = null;
            var min = double.MaxValue;
            foreach (var item in source)
            {
                var current = func(item);
                if (min > current)
                {
                    min = current;
                    result = item;
                }
            }
            return result;
        }

        public static T MaxBy<T>(this IEnumerable<T> source, Func<T, double> func, T defaultValue = default(T))
        {
            T result = defaultValue;
            var max = double.MinValue;
            foreach (var item in source)
            {
                var current = func(item);
                if (max < current)
                {
                    max = current;
                    result = item;
                }
            }
            return result;
        }

        public static string JoinStrings(this IEnumerable<string> source, string delimeter)
        {
            return string.Join(delimeter, source.ToArray());
        }

        public static string JoinStrings(this IEnumerable<int> source, string delimeter)
        {
            return source.Select(x => x.ToString()).JoinStrings(delimeter);
        }
    }
}

using System;
using System.Globalization;
using System.IO;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;
using System.Threading;

namespace Codeforces
{
    class Program : ProgramBase
    {
        private const long commonMod = 1000000007;

        static void Main(string[] args)
        {
            var p = new Program();
            var x = p.Get();
            p.Out(x);
        }

        object Get()
        {
            checked
            {
                //FileName = "input";
                var n = ReadLongToken();
                var m = ReadLongToken();
                var nlog = logbase7(n);
                var mlog = logbase7(m);
                if (nlog + mlog > 7)
                    return 0;
                var log = nlog + mlog;
                var hour = new int[nlog];
                var mins = new int[mlog];
                var counts = new int[7];
                counts[0] = (nlog + mlog);
                var bads = 1;
                var result = 0;

                var a = new int[7] { 0, 1, 2, 3, 4, 5, 6 };
                int[] prev = new int[7];
                while (NextPermutation(a))
                {
                    if (prev != null)
                    {
                        var fl = true;
                        for (int i = 0; i < log; i++)
                        {
                            if (a[i] != prev[i])
                            {
                                fl = false;
                                break;
                            }
                        }
                        if (fl)
                        {
                            continue;
                        }
                    }
                    var v = 0;
                    var pow = 1;
                    for (int i = 0; i < nlog; i++)
                    {
                        v += a[i] * pow;
                        pow *= 7;
                    }
                    if (v >= n)
                    {
                        Array.Copy(a, prev, 7);
                        continue;
                    }

                    pow = 1;
                    v = 0;
                    for (int i = 0; i < mlog; i++)
                    {
                        v += a[nlog + i] * pow;
                        pow *= 7;
                    }
                    if (v >= m)
                    {
                        Array.Copy(a, prev, 7);
                        continue;
                    }
                    result++;
                    Array.Copy(a, prev, 7);
                }
                return result;
            }

        }
        private static bool NextPermutation(int[] numList)
        {
            /*
             Knuths
             1. Find the largest index j such that a[j] < a[j + 1]. If no such index exists, the permutation is the last permutation.
             2. Find the largest index l such that a[j] < a[l]. Since j + 1 is such an index, l is well defined and satisfies j < l.
             3. Swap a[j] with a[l].
             4. Reverse the sequence from a[j + 1] up to and including the final element a[n].

             */
            var largestIndex = -1;
            for (var i = numList.Length - 2; i >= 0; i--)
            {
                if (numList[i] < numList[i + 1])
                {
                    largestIndex = i;
                    break;
                }
            }

            if (largestIndex < 0) return false;

            var largestIndex2 = -1;
            for (var i = numList.Length - 1; i >= 0; i--)
            {
                if (numList[largestIndex] < numList[i])
                {
                    largestIndex2 = i;
                    break;
                }
            }

            var tmp = numList[largestIndex];
            numList[largestIndex] = numList[largestIndex2];
            numList[largestIndex2] = tmp;

            for (int i = largestIndex + 1, j = numList.Length - 1; i < j; i++, j--)
            {
                tmp = numList[i];
                numList[i] = numList[j];
                numList[j] = tmp;
            }

            return true;
        }

        public int logbase7(long v)
        {
            var res = 0;
            v = v - 1;
            while(v > 0)
            {
                v /= 7;
                res++;
            }
            return res;
        }

        public static class Struct
        {
            public static Pair<T1, T2> Create<T1,T2>(T1 item1, T2 item2)
            {
                return new Pair<T1, T2> { Item1 = item1, Item2 = item2 };
            }
        }

        public struct Pair<T1, T2>
        {
            public T1 Item1 { get; set; }
            public T2 Item2 { get; set; }
        }

        class Automata
        {
            bool[] terminals;
            public int sigma;
            public int len;
            public int[,] jumps;

            public void Create()
            {
                var a = ReadInts();
                len = a[0];
                sigma = a[2];
                var ts = ReadInts();
                terminals = new bool[len];
                for (int i = 0; i < ts.Length; i++)
                    terminals[ts[i]] = true;
                jumps = new int[len, sigma];
                for (int i = 0; i < len * sigma; i++)
                {
                    var b = Console.ReadLine().Split(' ');
                    jumps[Convert.ToInt32(b[0]), b[1][0] - 'a'] = Convert.ToInt32(b[2]);
                }
            }
            protected int[] ReadInts()
            {
                return Console.ReadLine().Split(' ').Select(x => Convert.ToInt32(x)).ToArray();
            }

            public bool IsTerminal(int s)
            {
                return terminals[s];
            }
        }
    }

    abstract class ProgramBase
    {
        bool? prod = null;
        StreamReader f;
        Queue<string> tokens;
        protected string FileName { private get; set; }

        protected string Read()
        {
            if (f == null)
                f = string.IsNullOrEmpty(FileName)
                    ? new StreamReader(Console.OpenStandardInput())
                    : new StreamReader((GetProd() ? "" : "c:\\dev\\") + FileName);
            return f.ReadLine();
        }

        protected int ReadInt()
        {
            return int.Parse(Read());
        }

        protected int ReadIntToken()
        {
            if (tokens == null || tokens.Count == 0)
                tokens = new Queue<string>(Read().Split(' '));
            return int.Parse(tokens.Dequeue());
        }

        protected int[] ReadInts()
        {
            var tokens = Read().Split(' ');
            var result = new int[tokens.Length];
            for (int i = 0; i < tokens.Length; i++)
                result[i] = int.Parse(tokens[i]);
            return result;
        }

        protected long ReadLongToken()
        {
            if (tokens == null || tokens.Count == 0)
                tokens = new Queue<string>(Read().Split(' '));
            return long.Parse(tokens.Dequeue());
        }

        protected long ReadLong()
        {
            return Convert.ToInt64(Read());
        }

        protected long[] ReadLongs()
        {
            var tokens = Read().Split(' ');
            var result = new long[tokens.Length];
            for (int i = 0; i < tokens.Length; i++)
                result[i] = long.Parse(tokens[i]);
            return result;
        }

        public void Out(object r)
        {
            if (string.IsNullOrEmpty(FileName))
                Console.WriteLine(r);
            else if (GetProd())
                File.WriteAllText(FileName, r.ToString());
            else
                Console.WriteLine(r);
        }

        private bool GetProd()
        {

            if (!prod.HasValue)
                try
                {
                    prod = Environment.MachineName != "RENADEEN-W7";
                }
                catch (Exception)
                {
                    prod = true;
                }
            return prod.Value;
        }
    }

    public static class Huj
    {
        public static T MinBy<T>(this IEnumerable<T> source, Func<T, double> func) where T : class
        {
            T result = null;
            var min = double.MaxValue;
            foreach (var item in source)
            {
                var current = func(item);
                if (min > current)
                {
                    min = current;
                    result = item;
                }
            }
            return result;
        }

        public static T MaxBy<T>(this IEnumerable<T> source, Func<T, double> func, T defaultValue = default(T))
        {
            T result = defaultValue;
            var max = double.MinValue;
            foreach (var item in source)
            {
                var current = func(item);
                if (max < current)
                {
                    max = current;
                    result = item;
                }
            }
            return result;
        }

        public static string JoinStrings(this IEnumerable<string> source, string delimeter)
        {
            return string.Join(delimeter, source.ToArray());
        }

        public static string JoinStrings(this IEnumerable<int> source, string delimeter)
        {
            return source.Select(x => x.ToString()).JoinStrings(delimeter);
        }
    }
}

using System;
using System.Globalization;
using System.IO;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;
using System.Threading;

namespace Codeforces
{
    class Program : ProgramBase
    {
        private const long commonMod = 1000000007;

        static void Main(string[] args)
        {
            var p = new Program();
            var x = p.Get();
            p.Out(x);
        }

        object Get()
        {
            checked
            {
                //FileName = "input";
                var n = ReadLongToken();
                var m = ReadLongToken();
                var nlog = logbase7(n);
                var mlog = logbase7(m);
                if (nlog + mlog > 7)
                    return 0;
                var hour = new int[nlog];
                var mins = new int[mlog];
                var counts = new int[7];
                counts[0] = (nlog + mlog);
                var bads = 1;
                var result = 0;
                for (int i = 0; i < n; i++)
                {
                    for (int j = 0; j < m; j++)
                    {
                        if (bads == 0)
                            result++;
                        int digit = 0;
                        while(digit < mlog)
                        {
                            if (mins[digit] < 6)
                            {
                                counts[mins[digit]]--;
                                if (counts[mins[digit]] == 1)
                                    bads--;
                                mins[digit]++;
                                counts[mins[digit]]++;
                                if (counts[mins[digit]] == 2)
                                    bads++;
                                break;
                            }
                            else
                            {
                                counts[mins[digit]]--;
                                if (counts[mins[digit]] == 1)
                                    bads--;
                                mins[digit] = 0;
                                counts[mins[digit]]++;
                                if (counts[mins[digit]] == 2)
                                    bads++;
                            }
                            digit++;
                        }
                    }
                    for (int z = 0; z < mlog; z++)
                    {
                        counts[mins[z]]--;
                        if (counts[mins[z]] == 1)
                            bads--;
                        mins[z] = 0;
                        counts[mins[z]]++;
                        if (counts[mins[z]] == 2)
                            bads++;
                    }
                    var d = 0;
                    while (d < nlog)
                    {
                        if (hour[d] < 6)
                        {
                            counts[hour[d]]--;
                            if (counts[hour[d]] == 1)
                                bads--;
                            hour[d]++;
                            counts[hour[d]]++;
                            if (counts[hour[d]] == 2)
                                bads++;
                            break;
                        }
                        else
                        {
                            counts[hour[d]]--;
                            if (counts[hour[d]] == 1)
                                bads--;
                            hour[d] = 0;
                            counts[hour[d]]++;
                            if (counts[hour[d]] == 2)
                                bads++;
                        }
                        d++;
                    }

                }
                return result;
            }

        }

        public void AllSubsets(int all, int k)
        {

        }

        public int logbase7(long v)
        {
            var res = 0;
            v = v - 1;
            while(v > 0)
            {
                v /= 7;
                res++;
            }
            return res;
        }

        public static class Struct
        {
            public static Pair<T1, T2> Create<T1,T2>(T1 item1, T2 item2)
            {
                return new Pair<T1, T2> { Item1 = item1, Item2 = item2 };
            }
        }

        public struct Pair<T1, T2>
        {
            public T1 Item1 { get; set; }
            public T2 Item2 { get; set; }
        }

        class Automata
        {
            bool[] terminals;
            public int sigma;
            public int len;
            public int[,] jumps;

            public void Create()
            {
                var a = ReadInts();
                len = a[0];
                sigma = a[2];
                var ts = ReadInts();
                terminals = new bool[len];
                for (int i = 0; i < ts.Length; i++)
                    terminals[ts[i]] = true;
                jumps = new int[len, sigma];
                for (int i = 0; i < len * sigma; i++)
                {
                    var b = Console.ReadLine().Split(' ');
                    jumps[Convert.ToInt32(b[0]), b[1][0] - 'a'] = Convert.ToInt32(b[2]);
                }
            }
            protected int[] ReadInts()
            {
                return Console.ReadLine().Split(' ').Select(x => Convert.ToInt32(x)).ToArray();
            }

            public bool IsTerminal(int s)
            {
                return terminals[s];
            }
        }
    }

    abstract class ProgramBase
    {
        bool? prod = null;
        StreamReader f;
        Queue<string> tokens;
        protected string FileName { private get; set; }

        protected string Read()
        {
            if (f == null)
                f = string.IsNullOrEmpty(FileName)
                    ? new StreamReader(Console.OpenStandardInput())
                    : new StreamReader((GetProd() ? "" : "c:\\dev\\") + FileName);
            return f.ReadLine();
        }

        protected int ReadInt()
        {
            return int.Parse(Read());
        }

        protected int ReadIntToken()
        {
            if (tokens == null || tokens.Count == 0)
                tokens = new Queue<string>(Read().Split(' '));
            return int.Parse(tokens.Dequeue());
        }

        protected int[] ReadInts()
        {
            var tokens = Read().Split(' ');
            var result = new int[tokens.Length];
            for (int i = 0; i < tokens.Length; i++)
                result[i] = int.Parse(tokens[i]);
            return result;
        }

        protected long ReadLongToken()
        {
            if (tokens == null || tokens.Count == 0)
                tokens = new Queue<string>(Read().Split(' '));
            return long.Parse(tokens.Dequeue());
        }

        protected long ReadLong()
        {
            return Convert.ToInt64(Read());
        }

        protected long[] ReadLongs()
        {
            var tokens = Read().Split(' ');
            var result = new long[tokens.Length];
            for (int i = 0; i < tokens.Length; i++)
                result[i] = long.Parse(tokens[i]);
            return result;
        }

        public void Out(object r)
        {
            if (string.IsNullOrEmpty(FileName))
                Console.WriteLine(r);
            else if (GetProd())
                File.WriteAllText(FileName, r.ToString());
            else
                Console.WriteLine(r);
        }

        private bool GetProd()
        {

            if (!prod.HasValue)
                try
                {
                    prod = Environment.MachineName != "RENADEEN-W7";
                }
                catch (Exception)
                {
                    prod = true;
                }
            return prod.Value;
        }
    }

    public static class Huj
    {
        public static T MinBy<T>(this IEnumerable<T> source, Func<T, double> func) where T : class
        {
            T result = null;
            var min = double.MaxValue;
            foreach (var item in source)
            {
                var current = func(item);
                if (min > current)
                {
                    min = current;
                    result = item;
                }
            }
            return result;
        }

        public static T MaxBy<T>(this IEnumerable<T> source, Func<T, double> func, T defaultValue = default(T))
        {
            T result = defaultValue;
            var max = double.MinValue;
            foreach (var item in source)
            {
                var current = func(item);
                if (max < current)
                {
                    max = current;
                    result = item;
                }
            }
            return result;
        }

        public static string JoinStrings(this IEnumerable<string> source, string delimeter)
        {
            return string.Join(delimeter, source.ToArray());
        }

        public static string JoinStrings(this IEnumerable<int> source, string delimeter)
        {
            return source.Select(x => x.ToString()).JoinStrings(delimeter);
        }
    }
}

using System;
using System.Globalization;
using System.IO;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;
using System.Threading;

namespace Codeforces
{
    class Program : ProgramBase
    {
        private const long commonMod = 1000000007;

        static void Main(string[] args)
        {
            var p = new Program();
            var x = p.Get();
            p.Out(x);
        }

        object Get()
        {
            checked
            {
                //FileName = "input";
                var n = ReadLongToken();
                var m = ReadLongToken();
                var nlog = logbase7(n);
                var mlog = logbase7(m);
                if (nlog + mlog > 7)
                    return 0;
                var hour = new int[nlog];
                var mins = new int[mlog];
                var counts = new int[7];
                counts[0] = (nlog + mlog);
                var bads = 1;
                var result = 0;
                for (int i = 0; i < n; i++)
                {
                    for (int j = 0; j < m; j++)
                    {
                        if (bads == 0)
                            result++;
                        int digit = 0;
                        while(digit < mlog)
                        {
                            if (mins[digit] < 6)
                            {
                                counts[mins[digit]]--;
                                if (counts[mins[digit]] == 1)
                                    bads--;
                                mins[digit]++;
                                counts[mins[digit]]++;
                                if (counts[mins[digit]] == 2)
                                    bads++;
                                break;
                            }
                            else
                            {
                                counts[mins[digit]]--;
                                if (counts[mins[digit]] == 1)
                                    bads--;
                                mins[digit] = 0;
                                counts[mins[digit]]++;
                                if (counts[mins[digit]] == 2)
                                    bads++;
                            }
                            digit++;
                        }
                    }
                    for (int z = 0; z < mlog; z++)
                    {
                        counts[mins[z]]--;
                        if (counts[mins[z]] == 1)
                            bads--;
                        mins[z] = 0;
                        counts[mins[z]]++;
                        if (counts[mins[z]] == 2)
                            bads++;
                        break;
                    }
                    var d = 0;
                    while (d < nlog)
                    {
                        if (hour[d] < 6)
                        {
                            counts[hour[d]]--;
                            if (counts[hour[d]] == 1)
                                bads--;
                            hour[d]++;
                            counts[hour[d]]++;
                            if (counts[hour[d]] == 2)
                                bads++;
                            break;
                        }
                        else
                        {
                            counts[hour[d]]--;
                            if (counts[hour[d]] == 1)
                                bads--;
                            hour[d] = 0;
                            counts[hour[d]]++;
                            if (counts[hour[d]] == 2)
                                bads++;
                        }
                        d++;
                    }

                }
                return result;
            }

        }

        public void AllSubsets(int all, int k)
        {

        }

        public int logbase7(long v)
        {
            var res = 0;
            v = v - 1;
            while(v > 0)
            {
                v /= 7;
                res++;
            }
            return res;
        }

        public static class Struct
        {
            public static Pair<T1, T2> Create<T1,T2>(T1 item1, T2 item2)
            {
                return new Pair<T1, T2> { Item1 = item1, Item2 = item2 };
            }
        }

        public struct Pair<T1, T2>
        {
            public T1 Item1 { get; set; }
            public T2 Item2 { get; set; }
        }

        class Automata
        {
            bool[] terminals;
            public int sigma;
            public int len;
            public int[,] jumps;

            public void Create()
            {
                var a = ReadInts();
                len = a[0];
                sigma = a[2];
                var ts = ReadInts();
                terminals = new bool[len];
                for (int i = 0; i < ts.Length; i++)
                    terminals[ts[i]] = true;
                jumps = new int[len, sigma];
                for (int i = 0; i < len * sigma; i++)
                {
                    var b = Console.ReadLine().Split(' ');
                    jumps[Convert.ToInt32(b[0]), b[1][0] - 'a'] = Convert.ToInt32(b[2]);
                }
            }
            protected int[] ReadInts()
            {
                return Console.ReadLine().Split(' ').Select(x => Convert.ToInt32(x)).ToArray();
            }

            public bool IsTerminal(int s)
            {
                return terminals[s];
            }
        }
    }

    abstract class ProgramBase
    {
        bool? prod = null;
        StreamReader f;
        Queue<string> tokens;
        protected string FileName { private get; set; }

        protected string Read()
        {
            if (f == null)
                f = string.IsNullOrEmpty(FileName)
                    ? new StreamReader(Console.OpenStandardInput())
                    : new StreamReader((GetProd() ? "" : "c:\\dev\\") + FileName);
            return f.ReadLine();
        }

        protected int ReadInt()
        {
            return int.Parse(Read());
        }

        protected int ReadIntToken()
        {
            if (tokens == null || tokens.Count == 0)
                tokens = new Queue<string>(Read().Split(' '));
            return int.Parse(tokens.Dequeue());
        }

        protected int[] ReadInts()
        {
            var tokens = Read().Split(' ');
            var result = new int[tokens.Length];
            for (int i = 0; i < tokens.Length; i++)
                result[i] = int.Parse(tokens[i]);
            return result;
        }

        protected long ReadLongToken()
        {
            if (tokens == null || tokens.Count == 0)
                tokens = new Queue<string>(Read().Split(' '));
            return long.Parse(tokens.Dequeue());
        }

        protected long ReadLong()
        {
            return Convert.ToInt64(Read());
        }

        protected long[] ReadLongs()
        {
            var tokens = Read().Split(' ');
            var result = new long[tokens.Length];
            for (int i = 0; i < tokens.Length; i++)
                result[i] = long.Parse(tokens[i]);
            return result;
        }

        public void Out(object r)
        {
            if (string.IsNullOrEmpty(FileName))
                Console.WriteLine(r);
            else if (GetProd())
                File.WriteAllText(FileName, r.ToString());
            else
                Console.WriteLine(r);
        }

        private bool GetProd()
        {

            if (!prod.HasValue)
                try
                {
                    prod = Environment.MachineName != "RENADEEN-W7";
                }
                catch (Exception)
                {
                    prod = true;
                }
            return prod.Value;
        }
    }

    public static class Huj
    {
        public static T MinBy<T>(this IEnumerable<T> source, Func<T, double> func) where T : class
        {
            T result = null;
            var min = double.MaxValue;
            foreach (var item in source)
            {
                var current = func(item);
                if (min > current)
                {
                    min = current;
                    result = item;
                }
            }
            return result;
        }

        public static T MaxBy<T>(this IEnumerable<T> source, Func<T, double> func, T defaultValue = default(T))
        {
            T result = defaultValue;
            var max = double.MinValue;
            foreach (var item in source)
            {
                var current = func(item);
                if (max < current)
                {
                    max = current;
                    result = item;
                }
            }
            return result;
        }

        public static string JoinStrings(this IEnumerable<string> source, string delimeter)
        {
            return string.Join(delimeter, source.ToArray());
        }

        public static string JoinStrings(this IEnumerable<int> source, string delimeter)
        {
            return source.Select(x => x.ToString()).JoinStrings(delimeter);
        }
    }
}

using System;
using System.Globalization;
using System.IO;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;
using System.Threading;

namespace Codeforces
{
    class Program : ProgramBase
    {
        private const long commonMod = 1000000007;

        static void Main(string[] args)
        {
            var p = new Program();
            var x = p.Get();
            p.Out(x);
        }

        object Get()
        {
            checked
            {
                //FileName = "input";
                var n = ReadLongToken();
                var m = ReadLongToken();
                var nlog = logbase7(n);
                var mlog = logbase7(m);
                if (nlog + mlog > 7)
                    return 0;
                var log = nlog + mlog;
                var hour = new int[nlog];
                var mins = new int[mlog];
                var counts = new int[7];
                counts[0] = (nlog + mlog);
                var bads = 1;
                var result = 0;

                var a = new int[7] { 0, 1, 2, 3, 4, 5, 6 };
                int[] prev = new int[7];
                while (NextPermutation(a))
                {
                    if (prev != null)
                    {
                        var fl = true;
                        for (int i = 0; i < log; i++)
                        {
                            if (a[i] != prev[i])
                            {
                                fl = false;
                                break;
                            }
                        }
                        if (fl)
                        {
                            continue;
                        }
                    }
                    var v = 0;
                    var pow = 1;
                    for (int i = 0; i < nlog; i++)
                    {
                        v += a[i] * pow;
                        pow *= 7;
                    }
                    if (v >= n)
                        continue;

                    pow = 1;
                    v = 0;
                    for (int i = 0; i < mlog; i++)
                    {
                        v += a[nlog + i] * pow;
                        pow *= 7;
                    }
                    if (v >= m)
                        continue;
                    result++;
                    Array.Copy(a, prev, 7);
                }
                return result;
            }

        }
        private static bool NextPermutation(int[] numList)
        {
            /*
             Knuths
             1. Find the largest index j such that a[j] < a[j + 1]. If no such index exists, the permutation is the last permutation.
             2. Find the largest index l such that a[j] < a[l]. Since j + 1 is such an index, l is well defined and satisfies j < l.
             3. Swap a[j] with a[l].
             4. Reverse the sequence from a[j + 1] up to and including the final element a[n].

             */
            var largestIndex = -1;
            for (var i = numList.Length - 2; i >= 0; i--)
            {
                if (numList[i] < numList[i + 1])
                {
                    largestIndex = i;
                    break;
                }
            }

            if (largestIndex < 0) return false;

            var largestIndex2 = -1;
            for (var i = numList.Length - 1; i >= 0; i--)
            {
                if (numList[largestIndex] < numList[i])
                {
                    largestIndex2 = i;
                    break;
                }
            }

            var tmp = numList[largestIndex];
            numList[largestIndex] = numList[largestIndex2];
            numList[largestIndex2] = tmp;

            for (int i = largestIndex + 1, j = numList.Length - 1; i < j; i++, j--)
            {
                tmp = numList[i];
                numList[i] = numList[j];
                numList[j] = tmp;
            }

            return true;
        }

        public int logbase7(long v)
        {
            var res = 0;
            v = v - 1;
            while(v > 0)
            {
                v /= 7;
                res++;
            }
            return res;
        }

        public static class Struct
        {
            public static Pair<T1, T2> Create<T1,T2>(T1 item1, T2 item2)
            {
                return new Pair<T1, T2> { Item1 = item1, Item2 = item2 };
            }
        }

        public struct Pair<T1, T2>
        {
            public T1 Item1 { get; set; }
            public T2 Item2 { get; set; }
        }

        class Automata
        {
            bool[] terminals;
            public int sigma;
            public int len;
            public int[,] jumps;

            public void Create()
            {
                var a = ReadInts();
                len = a[0];
                sigma = a[2];
                var ts = ReadInts();
                terminals = new bool[len];
                for (int i = 0; i < ts.Length; i++)
                    terminals[ts[i]] = true;
                jumps = new int[len, sigma];
                for (int i = 0; i < len * sigma; i++)
                {
                    var b = Console.ReadLine().Split(' ');
                    jumps[Convert.ToInt32(b[0]), b[1][0] - 'a'] = Convert.ToInt32(b[2]);
                }
            }
            protected int[] ReadInts()
            {
                return Console.ReadLine().Split(' ').Select(x => Convert.ToInt32(x)).ToArray();
            }

            public bool IsTerminal(int s)
            {
                return terminals[s];
            }
        }
    }

    abstract class ProgramBase
    {
        bool? prod = null;
        StreamReader f;
        Queue<string> tokens;
        protected string FileName { private get; set; }

        protected string Read()
        {
            if (f == null)
                f = string.IsNullOrEmpty(FileName)
                    ? new StreamReader(Console.OpenStandardInput())
                    : new StreamReader((GetProd() ? "" : "c:\\dev\\") + FileName);
            return f.ReadLine();
        }

        protected int ReadInt()
        {
            return int.Parse(Read());
        }

        protected int ReadIntToken()
        {
            if (tokens == null || tokens.Count == 0)
                tokens = new Queue<string>(Read().Split(' '));
            return int.Parse(tokens.Dequeue());
        }

        protected int[] ReadInts()
        {
            var tokens = Read().Split(' ');
            var result = new int[tokens.Length];
            for (int i = 0; i < tokens.Length; i++)
                result[i] = int.Parse(tokens[i]);
            return result;
        }

        protected long ReadLongToken()
        {
            if (tokens == null || tokens.Count == 0)
                tokens = new Queue<string>(Read().Split(' '));
            return long.Parse(tokens.Dequeue());
        }

        protected long ReadLong()
        {
            return Convert.ToInt64(Read());
        }

        protected long[] ReadLongs()
        {
            var tokens = Read().Split(' ');
            var result = new long[tokens.Length];
            for (int i = 0; i < tokens.Length; i++)
                result[i] = long.Parse(tokens[i]);
            return result;
        }

        public void Out(object r)
        {
            if (string.IsNullOrEmpty(FileName))
                Console.WriteLine(r);
            else if (GetProd())
                File.WriteAllText(FileName, r.ToString());
            else
                Console.WriteLine(r);
        }

        private bool GetProd()
        {

            if (!prod.HasValue)
                try
                {
                    prod = Environment.MachineName != "RENADEEN-W7";
                }
                catch (Exception)
                {
                    prod = true;
                }
            return prod.Value;
        }
    }

    public static class Huj
    {
        public static T MinBy<T>(this IEnumerable<T> source, Func<T, double> func) where T : class
        {
            T result = null;
            var min = double.MaxValue;
            foreach (var item in source)
            {
                var current = func(item);
                if (min > current)
                {
                    min = current;
                    result = item;
                }
            }
            return result;
        }

        public static T MaxBy<T>(this IEnumerable<T> source, Func<T, double> func, T defaultValue = default(T))
        {
            T result = defaultValue;
            var max = double.MinValue;
            foreach (var item in source)
            {
                var current = func(item);
                if (max < current)
                {
                    max = current;
                    result = item;
                }
            }
            return result;
        }

        public static string JoinStrings(this IEnumerable<string> source, string delimeter)
        {
            return string.Join(delimeter, source.ToArray());
        }

        public static string JoinStrings(this IEnumerable<int> source, string delimeter)
        {
            return source.Select(x => x.ToString()).JoinStrings(delimeter);
        }
    }
}

using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;

namespace CF317
{
	internal class Program
	{
		private static void Main(string[] args)
		{
			var sr = new InputReader(Console.In);
			//var sr = new InputReader(new StreamReader("input.txt"));
			var task = new Task();
			using (var sw = Console.Out)
			//using (var sw = new StreamWriter("output.txt"))
			{
				task.Solve(sr, sw);
				//Console.ReadKey();
			}
		}
	}

	internal class Task
	{
		private long result = 0L;
		private List<int> daysInSeven;
		private List<int> minsInSeven;
		private string firstStr;
		private string secondStr;

		public void Solve(InputReader sr, TextWriter sw)
		{
			var input = sr.ReadArray(Int64.Parse);
			var n = input[0] - 1;
			var m = input[1] - 1;
			daysInSeven = ToSevenBase(n);
			minsInSeven = ToSevenBase(m);
			var reversed = daysInSeven.ToArray().Reverse();
			firstStr = reversed.Aggregate("", (curr, item) => curr + item);
			reversed = minsInSeven.ToArray().Reverse();
			secondStr = reversed.Aggregate("", (curr, item) => curr + item);
			var leftCount = daysInSeven.Count;
			var rightCount = minsInSeven.Count;
			if (leftCount + rightCount > 7) {
				rightCount -= 7 - leftCount;
			}
			if (rightCount < 0) {
				rightCount = 0;
			}
			Generate(0, 0, leftCount, rightCount, leftCount + rightCount, new char[leftCount + rightCount]);

			sw.WriteLine(result);
		}

		private void Generate(int currLeft, int currRight, int leftCount, int rightCount, int totalMax, char[] array)
		{
			if (currLeft + currRight == totalMax) {
				var contains = new int[7];
				for (var i = 0; i < array.Length; i++) {
					contains[array[i] - '0']++;
				}
				var isDifferent = contains.All(item => item <= 1);
				if (isDifferent) {
					var leftStr = new String(array, 0, leftCount);
					var rightStr = new String(array, leftCount, rightCount);
					var leftVal = String.IsNullOrEmpty(leftStr) ? 0L : Int64.Parse(leftStr);
					var rightVal = String.IsNullOrEmpty(rightStr) ? 0L : Int64.Parse(rightStr);
					var firstVal = String.IsNullOrEmpty(firstStr) ? 0L :Int64.Parse(firstStr);
					var secondVal = String.IsNullOrEmpty(secondStr) ? 0L : Int64.Parse(secondStr);
					if (leftVal <= firstVal && rightVal <= secondVal) {
						result++;
					}
				}
			}
			else {
				for (var i = 0; i < 7; i++) {
					array[currLeft + currRight] = (char) ('0' + i);
					if (currLeft < leftCount)
						Generate(currLeft + 1, currRight, leftCount, rightCount, totalMax, array);
					else
						Generate(currLeft, currRight + 1, leftCount, rightCount, totalMax, array);
				}
			}
		}

		private List<int> ToSevenBase(long n)
		{
			if (n == 0) {
				return new List<int> { 0 };
			}
			const int b = 7;
			var list = new List<int>();
			var curr = (int)n;
			while (curr > 0) {
				list.Add(curr % b);
				curr /= b;
			}

			return list;
		}
	}
}

internal class InputReader : IDisposable
{
	private bool isDispose;
	private readonly TextReader sr;

	public InputReader(TextReader stream)
	{
		sr = stream;
	}

	public void Dispose()
	{
		Dispose(true);
		GC.SuppressFinalize(this);
	}

	public string NextString()
	{
		var result = sr.ReadLine();
		return result;
	}

	public int NextInt32()
	{
		return Int32.Parse(NextString());
	}

	public long NextInt64()
	{
		return Int64.Parse(NextString());
	}

	public string[] NextSplitStrings()
	{
		return NextString()
			.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
	}

	public T[] ReadArray<T>(Func<string, CultureInfo, T> func)
	{
		return NextSplitStrings()
			.Select(s => func(s, CultureInfo.InvariantCulture))
			.ToArray();
	}

	public T[] ReadArrayFromString<T>(Func<string, CultureInfo, T> func, string str)
	{
		return
			str.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries)
				.Select(s => func(s, CultureInfo.InvariantCulture))
				.ToArray();
	}

	protected void Dispose(bool dispose)
	{
		if (!isDispose) {
			if (dispose)
				sr.Close();
			isDispose = true;
		}
	}

	~InputReader()
	{
		Dispose(false);
	}
}

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

namespace AlgoTraining.Codeforces.C_s
{
    public class FastScanner : StreamReader
    {
        private string[] _line;
        private int _iterator;

        public FastScanner(Stream stream) : base(stream)
        {
            _line = null;
            _iterator = 0;
        }
        public int NextInt()
        {
            if (_line == null || _iterator >= _line.Length)
            {
                _line = base.ReadLine().Split(' ');
                _iterator = 0;
            }
            if (_line.Count() == 0) throw new IndexOutOfRangeException("Input string is empty");
            return Convert.ToInt32(_line[_iterator++]);
        }
        public long NextLong()
        {
            if (_line == null || _iterator >= _line.Length)
            {
                _line = base.ReadLine().Split(' ');
                _iterator = 0;
            }
            if (_line.Count() == 0) throw new IndexOutOfRangeException("Input string is empty");
            return Convert.ToInt64(_line[_iterator++]);
        }
    }
    class AATask3
    {
        public static void Main(string[] args)
        {
            using (FastScanner fs = new FastScanner(new BufferedStream(Console.OpenStandardInput())))
            using (StreamWriter writer = new StreamWriter(new BufferedStream(Console.OpenStandardOutput())))
            {
                int n = fs.NextInt(), m = fs.NextInt();
                if (n > 823543 || m > 823543) writer.WriteLine(0);
                else
                {
                    List<string> hours = new List<string>(6000);
                    List<string> minutes = new List<string>(6000);
                    char[] nums = new char[] { '0', '1', '2', '3', '4', '5', '6' };
                    string maxHour = IntToStringFast(n, nums);
                    string maxMinute = IntToStringFast(m, nums);

                    for (int i = 0; i < n; i++)
                    {
                        StringBuilder sb = new StringBuilder(IntToStringFast(i, nums));
                        while (sb.Length < maxHour.Length) sb.Insert(0, 0);
                        string hour = sb.ToString();
                        if (IsUnique(hour))
                        {
                            hours.Add(hour);
                        }
                    }
                    for (int i = 0; i < m; i++)
                    {
                        StringBuilder sb = new StringBuilder(IntToStringFast(i, nums));
                        while (sb.Length < maxMinute.Length) sb.Insert(0, 0);
                        string minute = sb.ToString();
                        if (IsUnique(minute))
                        {
                            minutes.Add(minute);
                        }
                    }
                    int ans = 0;
                    foreach (string h in hours)
                    {
                        foreach (string min in minutes)
                        {
                            if (AreUnique(h, min))
                            {
                                ans++;
                            }
                        }
                    }
                    writer.WriteLine(ans);
                }
            }
        }

        private static bool AreUnique(string hour, string min)
        {
            bool[] count = new bool[7];
            for (int i = 0; i < hour.Length; i++)
            {
                count[hour[i] - '0'] = true;
            }
            for (int i = 0; i < min.Length; i++)
            {
                if (count[min[i] - '0']) return false;
            }
            return true;
        }

        private static bool IsUnique(string hour)
        {
            bool[] count = new bool[7];
            for (int i = 0; i < hour.Length; i++)
            {
                if (count[hour[i] - '0']) return false;
                else count[hour[i] - '0'] = true;
            }
            return true;
        }
        public static string IntToStringFast(int value, char[] baseChars)
        {
            // 32 is the worst cast buffer size for base 2 and int.MaxValue
            int i = 32;
            char[] buffer = new char[i];
            int targetBase = baseChars.Length;

            do
            {
                buffer[--i] = baseChars[value % targetBase];
                value = value / targetBase;
            }
            while (value > 0);

            char[] result = new char[32 - i];
            Array.Copy(buffer, i, result, 0, 32 - i);

            return new string(result);
        }
    }
}

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

namespace AlgoTraining.Codeforces.C_s
{
    public class FastScanner : StreamReader
    {
        private string[] _line;
        private int _iterator;

        public FastScanner(Stream stream) : base(stream)
        {
            _line = null;
            _iterator = 0;
        }
        public int NextInt()
        {
            if (_line == null || _iterator >= _line.Length)
            {
                _line = base.ReadLine().Split(' ');
                _iterator = 0;
            }
            if (_line.Count() == 0) throw new IndexOutOfRangeException("Input string is empty");
            return Convert.ToInt32(_line[_iterator++]);
        }
        public long NextLong()
        {
            if (_line == null || _iterator >= _line.Length)
            {
                _line = base.ReadLine().Split(' ');
                _iterator = 0;
            }
            if (_line.Count() == 0) throw new IndexOutOfRangeException("Input string is empty");
            return Convert.ToInt64(_line[_iterator++]);
        }
    }
    class AATask3
    {
        public static void Main(string[] args)
        {
            using (FastScanner fs = new FastScanner(new BufferedStream(Console.OpenStandardInput())))
            using (StreamWriter writer = new StreamWriter(new BufferedStream(Console.OpenStandardOutput())))
            {
                int n = fs.NextInt(), m = fs.NextInt();
                if (n > 823542 || m > 823542) writer.WriteLine(0);
                else
                {
                    List<string> hours = new List<string>(6000);
                    List<string> minutes = new List<string>(6000);
                    char[] nums = new char[] { '0', '1', '2', '3', '4', '5', '6' };
                    string maxHour = IntToStringFast(n, nums);
                    string maxMinute = IntToStringFast(m, nums);

                    for (int i = 0; i < n; i++)
                    {
                        StringBuilder sb = new StringBuilder(IntToStringFast(i, nums));
                        while (sb.Length < maxHour.Length) sb.Insert(0, 0);
                        string hour = sb.ToString();
                        if (IsUnique(hour))
                        {
                            hours.Add(hour);
                        }
                    }
                    for (int i = 0; i < m; i++)
                    {
                        StringBuilder sb = new StringBuilder(IntToStringFast(i, nums));
                        while (sb.Length < maxMinute.Length) sb.Insert(0, 0);
                        string minute = sb.ToString();
                        if (IsUnique(minute))
                        {
                            minutes.Add(minute);
                        }
                    }
                    int ans = 0;
                    foreach (string h in hours)
                    {
                        foreach (string min in minutes)
                        {
                            if (AreUnique(h, min))
                            {
                                ans++;
                            }
                        }
                    }
                    writer.WriteLine(ans);
                }
            }
        }

        private static bool AreUnique(string hour, string min)
        {
            bool[] count = new bool[7];
            for (int i = 0; i < hour.Length; i++)
            {
                count[hour[i] - '0'] = true;
            }
            for (int i = 0; i < min.Length; i++)
            {
                if (count[min[i] - '0']) return false;
            }
            return true;
        }

        private static bool IsUnique(string hour)
        {
            bool[] count = new bool[7];
            for (int i = 0; i < hour.Length; i++)
            {
                if (count[hour[i] - '0']) return false;
                else count[hour[i] - '0'] = true;
            }
            return true;
        }
        public static string IntToStringFast(int value, char[] baseChars)
        {
            // 32 is the worst cast buffer size for base 2 and int.MaxValue
            int i = 32;
            char[] buffer = new char[i];
            int targetBase = baseChars.Length;

            do
            {
                buffer[--i] = baseChars[value % targetBase];
                value = value / targetBase;
            }
            while (value > 0);

            char[] result = new char[32 - i];
            Array.Copy(buffer, i, result, 0, 32 - i);

            return new string(result);
        }
    }
}

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

namespace olimpSolve
{
    class Program
    {
        static void Main(string[] args)
        {
            var p = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
            int n = p[0];
            int m = p[1];
            double r1 = Math.Log(n, 7);
            double r2 = Math.Log(m, 7);
            int t1 = (int) Math.Ceiling(r1);
            int t2 = (int) Math.Ceiling(r2);
            int result = 0;
            for (int i = 0; i < Math.Min(n, 50); i++)
            {
                for (int j = 0; j < Math.Min(m, 50); j++)
                {
                    string str1 = ToSevenBase(i).PadLeft(t1, '0');
                    string str2 = ToSevenBase(j).PadLeft(t2, '0');
                    string str = str1 + str2;
                    if (str.ToCharArray().Distinct().Count() == str.Length)
                        result++;
                }
            }
            Console.WriteLine(result);
            Console.ReadLine();
        }

        private static string ToSevenBase(int n)
        {
            string p = string.Empty;
            while (n > 0)
            {
                p += (n % 7);
                n /= 7;
            }
            return p;
        }
    }
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Security.AccessControl;
using System.Text;
using System.Threading.Tasks;

namespace olimpSolve
{
    class Program
    {
        static void Main(string[] args)
        {
            var p = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
            int n = p[0];
            int m = p[1];
            int t1 = (int)Math.Ceiling(Math.Log(n, 7));
            int t2 = (int) Math.Ceiling(Math.Log(m, 7));
            int result = 0;
            if (t1 + t2 <= 7)
            {
                var arr = new List<int[]>();
                Generate(arr, 0, new int[t1 + t2]);
                foreach (var item in arr)
                {
                    int p1 = ToDec(item, 0, t1);
                    int p2 = ToDec(item,t1, item.Length);
                    if (p1 < n && p2 < m)
                        result++;
                    /*for (int i = 1; i < item.Length; i++)
                    {
                        int p1 = ToDec(item, 0, i);
                        int p2 = ToDec(item, i, item.Length);
                        if (p1 < n && p2 < m)
                            result++;
                    }*/
                }
            }
            Console.WriteLine(result);
            Console.ReadLine();
        }

        private static int ToDec(int[] arr, int l, int r)
        {
            int k = 0;
            for (int i = l; i < r; i++)
            {
                k = k * 7 + arr[i];
            }
            return k;
        }

        private static void Generate(List<int[]>arr , int index, int[] was)
        {
            if (index == was.Length)
            {
                arr.Add(was.ToArray());
            }
            else
            {
                for (int i = 0; i < 7; i++)
                {
                    if (!was.Take(index).Contains(i))
                    {
                        was[index] = i;
                        Generate(arr, index + 1, was);
                    }
                }
            }
        }
    }
}

/*
 * TemplateCS
 * Copyright (C) 2014-2016 Markus Himmel
 * This file is distributed under the terms of the MIT license
 */

//#define CodeJam
#define CodeForces

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

namespace ProgrammingCompetitions
{
	class Program
	{

#region GCJ
#if CodeJam
		private static bool DEBUG = false;

		static void debug()
		{
		}

		static string solveCase(int num)
		{
			checked
			{
				return null;
			}
		}
#endif
#endregion

#region CodeForces
#if CodeForces
#if DEBUG
		static Queue<string> testInput = new Queue<string>(new string[]
		{
			"2401 343",
		});
#endif

		static string Solve()
		{
			checked
			{
				int n, m;
				read(out n, out m);

				int h = 1;
				int nneed = 0;
				while (h < n)
				{
					nneed++;
					h *= 7;
				}
				h = 1;
				int mneed = 0;
				while (h < m)
				{
					mneed++;
					h *= 7;
				}
				if (mneed + nneed > 7)
					return "0";

				int res = 0;

				// at most 7^7
				for (int i = 0; i < n; i++)
				{
					for (int j = 0; j < m; j++)
					{
						HashSet<int> e = new HashSet<int>();
						bool o = false;
						int ii = i, jj = j;
						for (int nn = 0; nn < nneed; nn++)
						{
							if (!e.Add(ii % 7))
							{
								o = true;
								break;
							}
							ii /= 7;
						}
						if (o)
							continue;
						for (int mm = 0; mm < mneed; mm++)
						{
							if (!e.Add(jj % 7))
							{
								o = true;
								break;
							}
							jj /= 7;
						}
						if (!o)
						{
							res++;
						}
					}
				}
				return res.ToString();
			}
		}
#endif
#endregion

		// Everything after this comment is template code

		private static T read<T>()
		{
			return (T)Convert.ChangeType(read(), typeof(T));
		}

		private static T[] readMany<T>()
		{
			return readMany<T>(' ');
		}

		private static _[] readMany<_>(params char[] ___)
		{
			return read().Split(___).Select(__ => (_)Convert.ChangeType(__, typeof(_))).ToArray();
		}

		private static string[] readMany()
		{
			return readMany<string>();
		}

		private static T[][] readMany<T>(int n)
		{
			T[][] res = new T[n][];
			for (int i = 0; i < n; i++)
			{
				res[i] = readMany<T>();
			}
			return res;
		}

		private static T[][] readField<T>(int height, Func<char, T> map)
		{
			T[][] res = new T[height][];
			for (int _ = 0; _ < height; _++)
			{
				res[_] = read().Select(c => map(c)).ToArray();
			}
			return res;
		}

		private static char[][] readField(int height)
		{
			return readField(height, c => c);
		}

		private static T[][] readField<T>(int height, Dictionary<char, T> dic)
		{
			return readField(height, c => dic[c]);
		}

		private static void read<T1>(out T1 t1)
		{
			var vals = readMany();
			t1 = (T1)Convert.ChangeType(vals[0], typeof(T1));
		}

		private static void read<T1, T2>(out T1 t1, out T2 t2)
		{
			var vals = readMany();
			t1 = (T1)Convert.ChangeType(vals[0], typeof(T1));
			t2 = (T2)Convert.ChangeType(vals[1], typeof(T2));
		}

		private static void read<T1, T2, T3>(out T1 t1, out T2 t2, out T3 t3)
		{
			var vals = readMany();
			t1 = (T1)Convert.ChangeType(vals[0], typeof(T1));
			t2 = (T2)Convert.ChangeType(vals[1], typeof(T2));
			t3 = (T3)Convert.ChangeType(vals[2], typeof(T3));
		}

		private static void read<T1, T2, T3, T4>(out T1 t1, out T2 t2, out T3 t3, out T4 t4)
		{
			var vals = readMany();
			t1 = (T1)Convert.ChangeType(vals[0], typeof(T1));
			t2 = (T2)Convert.ChangeType(vals[1], typeof(T2));
			t3 = (T3)Convert.ChangeType(vals[2], typeof(T3));
			t4 = (T4)Convert.ChangeType(vals[3], typeof(T4));
		}

		private static void read<T1, T2, T3, T4, T5>(out T1 t1, out T2 t2, out T3 t3, out T4 t4, out T5 t5)
		{
			var vals = readMany();
			t1 = (T1)Convert.ChangeType(vals[0], typeof(T1));
			t2 = (T2)Convert.ChangeType(vals[1], typeof(T2));
			t3 = (T3)Convert.ChangeType(vals[2], typeof(T3));
			t4 = (T4)Convert.ChangeType(vals[3], typeof(T4));
			t5 = (T5)Convert.ChangeType(vals[4], typeof(T5));
		}

		static Func<T1, TResult> DP<T1, TResult>(Func<T1, Func<T1, TResult>, TResult> f)
		{
			var cache = new Dictionary<Tuple<T1>, TResult>();
			Func<T1, TResult> res = null;
			res = (t1) =>
			{
				var key = Tuple.Create(t1);
				if (!cache.ContainsKey(key))
					cache.Add(key, f(t1, res));
				return cache[key];
			};
			return res;
		}

		static Func<T1, T2, TResult> DP<T1, T2, TResult>(Func<T1, T2, Func<T1, T2, TResult>, TResult> f)
		{
			var cache = new Dictionary<Tuple<T1, T2>, TResult>();
			Func<T1, T2, TResult> res = null;
			res = (t1, t2) =>
			{
				var key = Tuple.Create(t1, t2);
				if (!cache.ContainsKey(key))
					cache.Add(key, f(t1, t2, res));
				return cache[key];
			};
			return res;
		}

		static Func<T1, T2, T3, TResult> DP<T1, T2, T3, TResult>(Func<T1, T2, T3, Func<T1, T2, T3, TResult>, TResult> f)
		{
			var cache = new Dictionary<Tuple<T1, T2, T3>, TResult>();
			Func<T1, T2, T3, TResult> res = null;
			res = (t1, t2, t3) =>
			{
				var key = Tuple.Create(t1, t2, t3);
				if (!cache.ContainsKey(key))
					cache.Add(key, f(t1, t2, t3, res));
				return cache[key];
			};
			return res;
		}

		static Func<T1, T2, T3, T4, TResult> DP<T1, T2, T3, T4, TResult>(Func<T1, T2, T3, T4, Func<T1, T2, T3, T4, TResult>, TResult> f)
		{
			var cache = new Dictionary<Tuple<T1, T2, T3, T4>, TResult>();
			Func<T1, T2, T3, T4, TResult> res = null;
			res = (t1, t2, t3, t4) =>
			{
				var key = Tuple.Create(t1, t2, t3, t4);
				if (!cache.ContainsKey(key))
					cache.Add(key, f(t1, t2, t3, t4, res));
				return cache[key];
			};
			return res;
		}

		static IEnumerable<T> single<T>(T it)
		{
			yield return it;
		}

		static IEnumerable<long> range(long first, long last, long step = 1)
		{
			for (long i = first; i <= last; i += step)
			{
				yield return i;
			}
		}

		static IEnumerable<int> range(int first, int last, int step = 1)
		{
			for (int i = first; i <= last; i+= step)
			{
				yield return i;
			}
		}

		static T id<T>(T a)
		{
			return a;
		}

		public static T[][] mkarr<T>(int x, int y)
		{
			T[][] res = new T[x][];
			for (int i = 0; i < x; i++)
			{
				res[i] = new T[y];
			}
			return res;
		}

		public static T[][][] mkarr<T>(int x, int y, int z)
		{
			T[][][] res = new T[x][][];
			for (int i = 0; i < x; i++)
			{
				res[i] = new T[y][];
				for (int j = 0; j < y; j++)
				{
					res[i][j] = new T[z];
				}
			}
			return res;
		}

		static bool[] tf = new[] { true, false };

#if CodeJam

		static void Main(string[] args)
		{
			if (DEBUG)
			{
				debug();
			}
			else
			{
				Initialize();
				SolveAll(solveCase);
			}
			Console.ReadKey();
		}

		private static StreamReader inf;
		private static StreamWriter outf;

		private delegate void o(string format, params object[] args);
		private static o Output;

		public static void Initialize()
		{
			Console.ForegroundColor = ConsoleColor.Yellow;
			Console.Write("File name: ");
			string name = Console.ReadLine();
			inf = new StreamReader($"D:\\Users\\marku\\Downloads\\{name}.in");
			outf = new StreamWriter($"D:\\Users\\marku\\Downloads\\{name}.out");
			Console.ForegroundColor = ConsoleColor.White;
			Output = highlightedPrint;
			Output += outf.WriteLine;
		}

		private static void highlightedPrint(string format, params object[] args)
		{
			ConsoleColor prev = Console.ForegroundColor;
			Console.ForegroundColor = ConsoleColor.Green;
			Console.WriteLine(format, args);
			Console.ForegroundColor = prev;
		}

		public static void SolveAll(Func<int, string> calc)
		{
			int cases = int.Parse(inf.ReadLine());
			for (int _ = 1; _ <= cases; _++)
			{
				Output($"Case #{_}: {calc(_)}");
			}
			inf.Close();
			outf.Close();
			Console.ForegroundColor = ConsoleColor.Cyan;
			Console.WriteLine("Eureka!");
		}

		private static string read()
		{
			return inf.ReadLine();
		}
#endif

#if CodeForces
		static void Main(string[] args)
		{
#if DEBUG
			var sw = new System.Diagnostics.Stopwatch();
			sw.Start();
#endif
			string s = Solve();
			if (!string.IsNullOrEmpty(s))
			{
				Console.WriteLine(s);
			}
#if DEBUG
			sw.Stop();
			Console.WriteLine(sw.Elapsed);
			Console.ReadKey();
#endif
		}

		private static string read()
		{
#if !DEBUG
			return Console.ReadLine();
#else
			return testInput.Dequeue();
#endif
		}
#endif
	}

	public static class ExtensionMethods
	{
		public static IEnumerable<TOut> Cartesian<T1, T2, TOut>(this IEnumerable<T1> first, IEnumerable<T2> second, Func<T1, T2, TOut> collector)
		{
			return first.SelectMany(f => second.Select(s => collector(f, s)));
		}

		public static IEnumerable<Tuple<T1, T2>> Cartesian<T1, T2>(this IEnumerable<T1> first, IEnumerable<T2> second)
		{
			return first.Cartesian(second, Tuple.Create);
		}

		public static IEnumerable<Tuple<T1, T2>> CartesianE<T1, T2>(this IEnumerable<T1> first, IEnumerable<T2> second)
		{
			// Calling CartesianE prevents selection of the wrong overload of Cartesian when you want a tuple of tuples to be returned
			return first.Cartesian(second);
		}

		public static IEnumerable<Tuple<T1, T2, T3>> Cartesian<T1, T2, T3>(this IEnumerable<Tuple<T1, T2>> first, IEnumerable<T3> second)
		{
			return first.Cartesian(second, (x, y) => Tuple.Create(x.Item1, x.Item2, y));
		}

		public static IEnumerable<Tuple<T1, T2, T3, T4>> Cartesian<T1, T2, T3, T4>(this IEnumerable<Tuple<T1, T2, T3>> first, IEnumerable<T4> second)
		{
			return first.Cartesian(second, (x, y) => Tuple.Create(x.Item1, x.Item2, x.Item3, y));
		}

		public static IEnumerable<Tuple<T1, T2, T3, T4, T5>> Cartesian<T1, T2, T3, T4, T5>(this IEnumerable<Tuple<T1, T2, T3, T4>> first, IEnumerable<T5> second)
		{
			return first.Cartesian(second, (x, y) => Tuple.Create(x.Item1, x.Item2, x.Item3, x.Item4, y));
		}

		public static IEnumerable<IEnumerable<T>> Cartesian<T>(this IEnumerable<IEnumerable<T>> source)
		{
			IEnumerable<IEnumerable<T>> res = source.First().Select(x => single(x));
			foreach (IEnumerable<T> next in source.Skip(1))
			{
				res = res.Cartesian(next, (sofar, n) => sofar.Concat(single(n)));
			}
			return res;
		}

		public static IEnumerable<IEnumerable<T>> Pow<T>(this IEnumerable<T> it, int num)
		{
			return Enumerable.Repeat(it, num).Cartesian();
		}

		public static IEnumerable<T> Demask<T>(this IEnumerable<Tuple<T, bool>> inp)
		{
			foreach (var pair in inp)
			{
				if (pair.Item2)
				{
					yield return pair.Item1;
				}
			}
		}

		public static IEnumerable<IEnumerable<IEnumerable<T>>> Partition<T>(this IEnumerable<T> source, int groups)
		{
			foreach (var part in Enumerable.Range(0, groups).Pow(source.Count()).Select(x => x.ToArray()))
			{
				yield return Enumerable.Range(0, groups).Select(x => source.Where((item, idx) => part[idx] == x));
			}
		}

		public static IEnumerable<IEnumerable<T>> Combinations<T>(this IEnumerable<T> it)
		{
			foreach (var conf in new[] { true, false }.Pow(it.Count()))
			{
				yield return it.Zip(conf, Tuple.Create).Demask();
			}
		}

		private static IEnumerable<T> single<T>(T it)
		{
			yield return it;
		}

		private static IEnumerable<T> ExceptSingle<T>(this IEnumerable<T> first, T it, IEqualityComparer<T> comp = null)
		{
			comp = comp ?? EqualityComparer<T>.Default;
			bool seen = false;
			foreach (T a in first)
			{
				if (!seen && comp.Equals(a, it))
				{
					seen = true;
				}
				else
				{
					yield return a;
				}
			}
		}

		public static IEnumerable<IEnumerable<T>> Permutations<T>(this IEnumerable<T> it)
		{
			if (it.Count() < 2)
			{
				yield return it;
				yield break;
			}

			foreach (T first in it)
			{
				foreach (IEnumerable<T> part in Permutations(it.ExceptSingle(first)))
				{
					yield return single(first).Concat(part);
				}
			}
		}

		public static T[][] Rho<T>(this IEnumerable<T> source, int x, int y)
		{
			T[][] res = Program.mkarr<T>(x, y);

			int i = 0, j = 0;

			while (true)
			{
				foreach (T item in source)
				{
					res[i][j] = item;
					j++;
					if (j == y)
					{
						j = 0;
						i++;
						if (i == x)
							break;
					}
				}
				if (i == x)
					break;
			}

			return res;
		}

		public static T[][][] Rho<T>(this IEnumerable<T> source, int x, int y, int z)
		{
			T[][][] res = Program.mkarr<T>(x, y, z);

			int i = 0, j = 0, k = 0;
			while (true)
			{
				foreach (T item in source)
				{
					res[i][j][k] = item;
					k++;
					if (k == z)
					{
						k = 0;
						j++;
						if (j == y)
						{
							j = 0;
							i++;
							if (i == x)
							{
								break;
							}
						}
					}
				}
				if (i == x)
					break;
			}

			return res;
		}
	}
}

using System;
using System.IO;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;

class Program
{
    bool[] a = new bool[7];
    bool Check(int x, int v)
    {
        return x < v;
    }

    int GetCount(int k)
    {
        k--;
        int count = 0;
        for (;;)
        {
            count++;
            k /= 7;
            if (k == 0)
                return count;
        }
    }

    //////////////////////////////////////////////////
    void Solution()
    {
        var n = ri;
        var m = ri;

        var countN = GetCount(n);
        var countM = GetCount(m);
        var count = countM + countN;

        if (count > 7)
        {
            wln(0);
            return;
        }

        int res = 0;
        int first = 0;
        int countF = 0;
        int second = 0;
        int countS = 0;
        for (int i0 = 0; i0 < 7; i0++)
        {
            if (a[i0]) continue;
            a[i0] = true;
            int t0;
            if (countF == countN)
            {
                if (countS == countM)
                {
                    a[i0] = false;
                    if (Check(first, n) && Check(second, m))
                        res++;
                    break;
                }
                else
                {
                    second = second * 10 + i0;
                    t0 = 2;
                    countS++;
                }
            }
            else
            {
                first = first * 10 + i0;
                t0 = 1;
                countF++;
            }
            for (int i1 = 0; i1 < 7; i1++)
            {
                if (a[i1]) continue;
                a[i1] = true;
                int t1;
                if (countF == countN)
                {
                    if (countS == countM)
                    {
                        a[i1] = false;
                        if (Check(first, n) && Check(second, m))
                            res++;
                        break;
                    }
                    else
                    {
                        second = second * 10 + i1;
                        t1 = 2;
                        countS++;
                    }
                }
                else
                {
                    first = first * 10 + i1;
                    t1 = 1;
                    countF++;
                }
                for (int i2 = 0; i2 < 7; i2++)
                {
                    if (a[i2]) continue;
                    a[i2] = true;
                    int t2;
                    if (countF == countN)
                    {
                        if (countS == countM)
                        {
                            a[i2] = false;
                            if (Check(first, n) && Check(second, m))
                                res++;
                            break;
                        }
                        else
                        {
                            second = second * 10 + i2;
                            t2 = 2;
                            countS++;
                        }
                    }
                    else
                    {
                        first = first * 10 + i2;
                        t2 = 1;
                        countF++;
                    }
                    for (int i3 = 0; i3 < 7; i3++)
                    {
                        if (a[i3]) continue;
                        a[i3] = true;
                        int t3;
                        if (countF == countN)
                        {
                            if (countS == countM)
                            {
                                a[i3] = false;
                                if (Check(first, n) && Check(second, m))
                                    res++;
                                break;
                            }
                            else
                            {
                                second = second * 10 + i3;
                                t3 = 2;
                                countS++;
                            }
                        }
                        else
                        {
                            first = first * 10 + i3;
                            t3 = 1;
                            countF++;
                        }
                        for (int i4 = 0; i4 < 7; i4++)
                        {
                            if (a[i4]) continue;
                            a[i4] = true;
                            int t4;
                            if (countF == countN)
                            {
                                if (countS == countM)
                                {
                                    a[i4] = false;
                                    if (Check(first, n) && Check(second, m))
                                        res++;
                                    break;
                                }
                                else
                                {
                                    second = second * 10 + i4;
                                    t4 = 2;
                                    countS++;
                                }
                            }
                            else
                            {
                                first = first * 10 + i4;
                                t4 = 1;
                                countF++;
                            }
                            for (int i5 = 0; i5 < 7; i5++)
                            {
                                if (a[i5]) continue;
                                a[i5] = true;
                                int t5;
                                if (countF == countN)
                                {
                                    if (countS == countM)
                                    {
                                        a[i5] = false;
                                        if (Check(first, n) && Check(second, m))
                                            res++;
                                        break;
                                    }
                                    else
                                    {
                                        second = second * 10 + i5;
                                        t5 = 2;
                                        countS++;
                                    }
                                }
                                else
                                {
                                    first = first * 10 + i5;
                                    t5 = 1;
                                    countF++;
                                }
                                for (int i6 = 0; i6 < 7; i6++)
                                {
                                    if (a[i6]) continue;
                                    if (Check(first, n) && Check(second, m))
                                        res++;
                                }
                                a[i5] = false;

                                if (t5 == 1)
                                {
                                    countF--;
                                    first /= 10;
                                }
                                else
                                {
                                    countS--;
                                    second /= 10;
                                }
                            }
                            a[i4] = false;
                            if (t4 == 1)
                            {
                                countF--;
                                first /= 10;
                            }
                            else
                            {
                                countS--;
                                second /= 10;
                            }
                        }
                        a[i3] = false;
                        if (t3 == 1)
                        {
                            countF--;
                            first /= 10;
                        }
                        else
                        {
                            countS--;
                            second /= 10;
                        }
                    }
                    a[i2] = false;
                    if (t2 == 1)
                    {
                        countF--;
                        first /= 10;
                    }
                    else
                    {
                        countS--;
                        second /= 10;
                    }
                }
                a[i1] = false;
                if (t1 == 1)
                {
                    countF--;
                    first /= 10;
                }
                else
                {
                    countS--;
                    second /= 10;
                }
            }
            a[i0] = false;
            if (t0 == 1)
            {
                countF--;
                first /= 10;
            }
            else
            {
                countS--;
                second /= 10;
            }
        }
        wln(res);
    }
    //////////////////////////////////////////////////

    static void swap(ref object o1, ref object o2) { var o = o1; o1 = o2; o2 = o; }
    static void wln(object o = null) { Console.WriteLine(o); }
    static void wsp(object o) { Console.Write(o + " "); }
    static void wrt(object o) { Console.Write(o); }
    //Console.Write(string.Format(CultureInfo.InvariantCulture, "{0:F12}", o));

    static long gcd(long a, long b) { return (b != 0) ? gcd(b, a % b) : a; }
    static long lcm(long a, long b) { return a / gcd(a, b) * b; }

    int ri
    {
        get
        {
            _read(); while (_str[_ind] == ' ') ++_ind;
            int sign = 1; if (_str[_ind] == '-') { sign = -1; ++_ind; }
            int p = 0;
            while (_ind < _count && _str[_ind] != ' ') p = p * 10 + _str[_ind++] - '0';
            while (_ind < _count && _str[_ind] == ' ') ++_ind; return p * sign;
        }
    }
    long rl
    {
        get
        {
            _read(); while (_str[_ind] == ' ') ++_ind;
            int sign = 1; if (_str[_ind] == '-') { sign = -1; ++_ind; }
            long p = 0;
            while (_ind < _count && _str[_ind] != ' ') p = p * 10 + _str[_ind++] - '0';
            while (_ind < _count && _str[_ind] == ' ') ++_ind; return p * sign;
        }
    }
    double rd
    {
        get
        {
            _read(); while (_str[_ind] == ' ') ++_ind; int sign = 1; if (_str[_ind] == '-') { sign = -1; ++_ind; }
            long p = 0, q = 1; while (_ind < _count && _str[_ind] != ' ' && _str[_ind] != '.') p = p * 10 + _str[_ind++] - '0';
            if (_ind < _count && _str[_ind] == '.') { ++_ind; while (_ind < _count && _str[_ind] != ' ') { p = p * 10 + _str[_ind++] - '0'; q *= 10; } }
            while (_ind < _count && _str[_ind] == ' ') ++_ind; return (double)p / q * sign;
        }
    }
    string rs
    {
        get
        {
            _read(); while (_ind < _count && _str[_ind] == ' ') ++_ind;
            var tmp = _str.IndexOf(' ', _ind);
            if (tmp == -1) { _count = 0; _ind = 0; return _str.Substring(_ind); }
            var s = _str.Substring(_ind, tmp - _ind); _ind = tmp + 1;
            while (_ind < _count && _str[_ind] == ' ') ++_ind; return s;
        }
    }

    int[] ria(int n)
    {
        var res = new int[n];
        for (int k = 0; k < n;)
        {
            var s = Console.ReadLine(); var m = s.Length;
            for (int i = 0; i < m && k < n; ++i)
            {
                while (i < m && s[i] == ' ') ++i; if (i == m) break; int sign = 1; if (s[i] == '-') { sign = -1; ++i; }
                int p = 0; while (i < m && s[i] != ' ') p = p * 10 + s[i++] - '0'; res[k++] = p * sign;
            }
        }
        _count = 0; _ind = 0; return res;
    }
    long[] rla(int n)
    {
        var res = new long[n];
        for (int k = 0; k < n;)
        {
            var s = Console.ReadLine(); var m = s.Length;
            for (int i = 0; i < m && k < n; ++i)
            {
                while (i < m && s[i] == ' ') ++i; if (i == m) break; int sign = 1; if (s[i] == '-') { sign = -1; ++i; }
                long p = 0; while (i < m && s[i] != ' ') p = p * 10 + s[i++] - '0'; res[k++] = p * sign;
            }
        }
        _count = 0; _ind = 0; return res;
    }
    double[] rda(int n)
    {
        var res = new double[n];
        for (int k = 0; k < n;)
        {
            var s = Console.ReadLine(); var m = s.Length;
            for (int i = 0; i < m && k < n; ++i)
            {
                while (i < m && s[i] == ' ') ++i; if (i == m) break; int sign = 1; if (s[i] == '-') { sign = -1; ++i; }
                long p = 0, q = 1; while (i < m && s[i] != ' ' && s[i] != '.') p = p * 10 + s[i++] - '0';
                if (i < m && s[i] == '.') { ++i; while (i < m && s[i] != ' ') { p = p * 10 + s[i++] - '0'; q *= 10; } }
                res[k++] = (double)p / q * sign;
            }
        }
        _count = 0; _ind = 0; return res;
    }
    string[] rsa(int n) { var res = new string[n]; for (int k = 0; k < n; ++k) res[k] = Console.ReadLine(); _count = 0; _ind = 0; return res; }
    string _str = null; int _count = 0; int _ind = 0;
    void _read() { if (_ind == _count) { _str = Console.ReadLine(); _count = _str.Length; _ind = 0; } }
    static void Main() { new Program().Solution(); }
}

using System;
using System.IO;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;

class Program
{
    bool[] a = new bool[7];
    bool Check(int x, int v)
    {
        return x < v;
    }

    int GetCount(int k)
    {
        k--;
        int count = 0;
        for (;;)
        {
            count++;
            k /= 7;
            if (k == 0)
                return count;
        }
    }
    int n;
    int m;
    int countN;
    int countM;
    int res;

    //(0,0)
    void tutuFirst(int first, int countF)
    {
        if (countF == countN)
        {
            if (Check(first, n))
            {
                tutuSecond(0, 0);
            }
            return;
        }
        for (int j = 0; j < 7; j++)
        {
            if (a[j]) continue;
            a[j] = true;
            tutuFirst(first * 10 + j, countF + 1);
            a[j] = false;
        }
    }
    void tutuSecond(int second, int countS)
    {
        if (countS == countM)
        {
            if (Check(second, m))
            {
                res++;
            }
            return;
        }
        for (int j = 0; j < 7; j++)
        {
            if (a[j]) continue;
            a[j] = true;
            tutuSecond(second * 10 + j, countS + 1);
            a[j] = false;
        }
    }

    //////////////////////////////////////////////////
    void Solution()
    {
        n = ri;
        m = ri;

        countN = GetCount(n);
        countM = GetCount(m);
        var count = countM + countN;

        if (count > 7)
        {
            wln(0);
            return;
        }

        res = 0;
        tutuFirst(0, 0);
        wln(res);
    }
    //////////////////////////////////////////////////

    static void swap(ref object o1, ref object o2) { var o = o1; o1 = o2; o2 = o; }
    static void wln(object o = null) { Console.WriteLine(o); }
    static void wsp(object o) { Console.Write(o + " "); }
    static void wrt(object o) { Console.Write(o); }
    //Console.Write(string.Format(CultureInfo.InvariantCulture, "{0:F12}", o));

    static long gcd(long a, long b) { return (b != 0) ? gcd(b, a % b) : a; }
    static long lcm(long a, long b) { return a / gcd(a, b) * b; }

    int ri
    {
        get
        {
            _read(); while (_str[_ind] == ' ') ++_ind;
            int sign = 1; if (_str[_ind] == '-') { sign = -1; ++_ind; }
            int p = 0;
            while (_ind < _count && _str[_ind] != ' ') p = p * 10 + _str[_ind++] - '0';
            while (_ind < _count && _str[_ind] == ' ') ++_ind; return p * sign;
        }
    }
    long rl
    {
        get
        {
            _read(); while (_str[_ind] == ' ') ++_ind;
            int sign = 1; if (_str[_ind] == '-') { sign = -1; ++_ind; }
            long p = 0;
            while (_ind < _count && _str[_ind] != ' ') p = p * 10 + _str[_ind++] - '0';
            while (_ind < _count && _str[_ind] == ' ') ++_ind; return p * sign;
        }
    }
    double rd
    {
        get
        {
            _read(); while (_str[_ind] == ' ') ++_ind; int sign = 1; if (_str[_ind] == '-') { sign = -1; ++_ind; }
            long p = 0, q = 1; while (_ind < _count && _str[_ind] != ' ' && _str[_ind] != '.') p = p * 10 + _str[_ind++] - '0';
            if (_ind < _count && _str[_ind] == '.') { ++_ind; while (_ind < _count && _str[_ind] != ' ') { p = p * 10 + _str[_ind++] - '0'; q *= 10; } }
            while (_ind < _count && _str[_ind] == ' ') ++_ind; return (double)p / q * sign;
        }
    }
    string rs
    {
        get
        {
            _read(); while (_ind < _count && _str[_ind] == ' ') ++_ind;
            var tmp = _str.IndexOf(' ', _ind);
            if (tmp == -1) { _count = 0; _ind = 0; return _str.Substring(_ind); }
            var s = _str.Substring(_ind, tmp - _ind); _ind = tmp + 1;
            while (_ind < _count && _str[_ind] == ' ') ++_ind; return s;
        }
    }

    int[] ria(int n)
    {
        var res = new int[n];
        for (int k = 0; k < n;)
        {
            var s = Console.ReadLine(); var m = s.Length;
            for (int i = 0; i < m && k < n; ++i)
            {
                while (i < m && s[i] == ' ') ++i; if (i == m) break; int sign = 1; if (s[i] == '-') { sign = -1; ++i; }
                int p = 0; while (i < m && s[i] != ' ') p = p * 10 + s[i++] - '0'; res[k++] = p * sign;
            }
        }
        _count = 0; _ind = 0; return res;
    }
    long[] rla(int n)
    {
        var res = new long[n];
        for (int k = 0; k < n;)
        {
            var s = Console.ReadLine(); var m = s.Length;
            for (int i = 0; i < m && k < n; ++i)
            {
                while (i < m && s[i] == ' ') ++i; if (i == m) break; int sign = 1; if (s[i] == '-') { sign = -1; ++i; }
                long p = 0; while (i < m && s[i] != ' ') p = p * 10 + s[i++] - '0'; res[k++] = p * sign;
            }
        }
        _count = 0; _ind = 0; return res;
    }
    double[] rda(int n)
    {
        var res = new double[n];
        for (int k = 0; k < n;)
        {
            var s = Console.ReadLine(); var m = s.Length;
            for (int i = 0; i < m && k < n; ++i)
            {
                while (i < m && s[i] == ' ') ++i; if (i == m) break; int sign = 1; if (s[i] == '-') { sign = -1; ++i; }
                long p = 0, q = 1; while (i < m && s[i] != ' ' && s[i] != '.') p = p * 10 + s[i++] - '0';
                if (i < m && s[i] == '.') { ++i; while (i < m && s[i] != ' ') { p = p * 10 + s[i++] - '0'; q *= 10; } }
                res[k++] = (double)p / q * sign;
            }
        }
        _count = 0; _ind = 0; return res;
    }
    string[] rsa(int n) { var res = new string[n]; for (int k = 0; k < n; ++k) res[k] = Console.ReadLine(); _count = 0; _ind = 0; return res; }
    string _str = null; int _count = 0; int _ind = 0;
    void _read() { if (_ind == _count) { _str = Console.ReadLine(); _count = _str.Length; _ind = 0; } }
    static void Main() { new Program().Solution(); }
}

// using a C# contest template, relevant code is at the bottom in the Run() function

using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Text;

class ProblemA {
    static string inputFileName = "../../input.txt";
    static StreamReader fileReader;
    static string[] inputTokens;
    static int curInputTokenIndex;
    static bool isLocal = Type.GetType("HaitaoLocal") != null;
    static string NextToken() {
        string ret = "";
        while (ret == "") {
            if (inputTokens == null || curInputTokenIndex >= inputTokens.Length) {
                string line;
                if (isLocal) {
                    line = fileReader.ReadLine();
                    if (line == null) {
                        throw new Exception("Error: out of input tokens!");
                    }
                } else {
                    line = Console.ReadLine();
                }
                inputTokens = line.Split();
                curInputTokenIndex = 0;
            }
            ret = inputTokens[curInputTokenIndex++];
        }
        return ret;
    }
    static int ri { get { return RI(); } }
    static string rs { get { return RS(); } }
    static long rl { get { return RL(); } }
    static double rd { get { return RD(); } }
    static int RI() {
        return Int32.Parse(NextToken());
    }
    static string RS() {
        return NextToken();
    }
    static long RL() {
        return Int64.Parse(NextToken());
    }
    static double RD() {
        return Double.Parse(NextToken());
    }
    static int[] RIA(int length) {
        int[] ret = new int[length];
        for (int i = 0; i < length; i++) {
            ret[i] = RI();
        }
        return ret;
    }
    static string[] RSA(int length) {
        string[] ret = new string[length];
        for (int i = 0; i < length; i++) {
            ret[i] = RS();
        }
        return ret;
    }
    static long[] RLA(int length) {
        long[] ret = new long[length];
        for (int i = 0; i < length; i++) {
            ret[i] = RL();
        }
        return ret;
    }
    static double[] RDA(int length) {
        double[] ret = new double[length];
        for (int i = 0; i < length; i++) {
            ret[i] = RD();
        }
        return ret;
    }
    static StringBuilder outputBuilder;
    static CultureInfo outputCulture = new CultureInfo("en-US");
    static void Out(object obj) {
        Type type = obj.GetType();
        string str = obj.ToString();
        if (type == typeof(double) || type == typeof(float)) {
            str = ((double)obj).ToString(outputCulture);
        }
        outputBuilder.Append(str + " ");
    }
    static void Outl() {
        Outl("");
    }
    static void Outl(object obj) {
        Out(obj);
        outputBuilder.Append("\n");
    }
    static void Flush() {
        if (isLocal) {
            ConsoleColor t = Console.ForegroundColor;
            Console.ForegroundColor = ConsoleColor.Green;
            Console.WriteLine();
            Console.WriteLine(outputBuilder.ToString());
            Console.ForegroundColor = t;
        } else {
            Console.WriteLine(outputBuilder.ToString());
        }
        outputBuilder = new StringBuilder();
    }
    static void Log(string label, object obj) {
        if (!isLocal) return;

        ConsoleColor t = Console.ForegroundColor;
        Console.ForegroundColor = ConsoleColor.Gray;
        Console.Write(label + ": ");
        Console.ForegroundColor = t;
        Log(obj);
    }
    static void Log(object obj) {
        if (!isLocal) return;

        ConsoleColor t = Console.ForegroundColor;
        Console.ForegroundColor = ConsoleColor.White;
        Console.WriteLine(ToStringRecursive(obj));
        Console.ForegroundColor = t;
    }
    static string ToStringRecursive(object obj) {
        StringBuilder sb = new StringBuilder();
        if (!(obj is string) && (obj is System.Collections.IEnumerable)) {
            System.Collections.IEnumerable en = obj as System.Collections.IEnumerable;
            sb.Append("{");
            bool first = true;
            foreach (object el in en) {
                if (!first) sb.Append(", ");
                sb.Append(ToStringRecursive(el));
                first = false;
            }
            sb.Append("}");
            return sb.ToString();
        }
        return obj.ToString();
    }

    public static void Main(string[] args) {
        long startTick = 0;
        if (isLocal) {
            startTick = Environment.TickCount;
            fileReader = new StreamReader(inputFileName);
        }

        outputBuilder = new StringBuilder();
        Run();
        if (isLocal) {
            ConsoleColor t = Console.ForegroundColor;
            Console.ForegroundColor = ConsoleColor.Green;
            Console.WriteLine();
            Console.WriteLine(outputBuilder.ToString());
            Console.WriteLine();
            Console.ForegroundColor = t;
        } else {
            Console.WriteLine(outputBuilder.ToString());
        }

        if (isLocal) {
            long runTime = Environment.TickCount - startTick;
            if (runTime > 32) {
                Log("time", runTime);
                Log("");
            }
        }
    }

    static void Run() {
        long n = rl;
        long m = rl;
        int nd = 0;
        long tn = n;
        while (tn > 0) {
            tn /= 7;
            nd++;
        }
        int md = 0;
        long tm = m;
        while (tm > 0) {
            tm /= 7;
            md++;
        }
        if (nd + md > 7) Outl(0);
        else {
            long ans = 0;
            for (int a = 0; a < n; a++) {
                for (int b = 0; b < m; b++) {
                    bool[] x = new bool[7];
                    List<int> l = new List<int>();
                    int ta = a;
                    while (ta > 0) {
                        l.Add(ta % 7);
                        ta /= 7;
                    }
                    int tb = b;
                    while (tb > 0) {
                        l.Add(tb % 7);
                        tb /= 7;
                    }
                    if (l.Count < nd + md) {
                        l.Add(0);
                    }
                    if (l.Count < nd + md) {
                        continue;
                    }
                    bool flag = true;
                    foreach (int i in l) {
                        if (x[i]) {
                            flag = false; break;
                        }
                        x[i] = true;
                    }
                    if(flag) {
                        ans++;
                    }
                }
            }
            Outl(ans);
        }

    }
}

using System;
using System.Collections.Generic;
using System.IO;
using System.Text;

namespace Robbers__watch
{
    internal class Program
    {
        private static readonly StreamReader reader = new StreamReader(Console.OpenStandardInput(1024*10), Encoding.ASCII, false, 1024*10);
        private static readonly StreamWriter writer = new StreamWriter(Console.OpenStandardOutput(1024*10), Encoding.ASCII, 1024*10);

        private static void Main(string[] args)
        {
            int n = Next();
            int m = Next();

            int cn = Digits(n);
            int cm = Digits(m);

            var p = new[] {0, 1, 2, 3, 4, 5, 6};
            int count = 0;
            HashSet<long> h = new HashSet<long>();

            if (cn + cm <= p.Length)
            {
                do
                {
                    int i = 0;
                    long nn = 0, mm = 0;
                    for (int j = 0; j < cn; j++)
                    {
                        nn = nn*7 + p[i];
                        i++;
                    }
                    for (int j = 0; j < cm; j++)
                    {
                        mm = mm*7 + p[i];
                        i++;
                    }
                    if (nn < n && mm < m)
                    {
                        long key = (nn << 32) + mm;
                        if (h.Add(key))
                            count++;
                    }
                } while (NextPermutation(p));
            }

            writer.WriteLine(count);
            writer.Flush();
        }

        private static int Digits(int n)
        {
            if (n == 0)
                return 1;
            int count = 0;
            while (n > 0)
            {
                n /= 7;
                count++;
            }
            return count;
        }

        private static bool NextPermutation(int[] nn)
        {
            if (nn.Length <= 1) return false;
            int i = nn.Length - 1;
            int last = nn.Length;

            while (true)
            {
                int i1 = i;
                if (nn[--i] < nn[i1])
                {
                    int i2 = last;
                    while (!(nn[i] < nn[--i2]))
                    {
                        ;
                    }
                    int c = nn[i];
                    nn[i] = nn[i2];
                    nn[i2] = c;

                    Reverse(nn, i1, last);
                    return true;
                }
                if (i == 0)
                {
                    Reverse(nn, 0, last);
                    return false;
                }
            }
        }

        private static void Reverse(int[] nn, int first, int last)
        {
            while ((first != last) && (first != --last))
            {
                int c = nn[first];
                nn[first] = nn[last];
                nn[last] = c;
                first++;
            }
        }

        private static int Next()
        {
            int c;
            int res = 0;
            do
            {
                c = reader.Read();
                if (c == -1)
                    return res;
            } while (c < '0' || c > '9');
            res = c - '0';
            while (true)
            {
                c = reader.Read();
                if (c < '0' || c > '9')
                    return res;
                res *= 10;
                res += c - '0';
            }
        }
    }
}

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

// (づ°ω°)づﾐe★゜・。。・゜゜・。。・゜☆゜・。。・゜゜・。。・゜
public class Solver
{
    List<int> Fun(int x)
    {
        var ret = new List<int>();
        while (x > 0)
        {
            ret.Add(x % 7);
            x /= 7;
        }
        ret.Reverse();
        return ret;
    }

    public void Solve()
    {
        int n = ReadInt();
        int m = ReadInt();

        var dp = new int[1 << 7, 2];
        dp[0, 0] = 1;
        foreach (int x in Fun(n - 1))
        {
            var ndp = new int[1 << 7, 2];
            for (int i = 0; i < 1 << 7; i++)
                for (int j = 0; j < 2; j++)
                    for (int k = 0; k < 7; k++)
                        if ((i >> k & 1) == 0)
                        {
                            if (j == 0 && k > x)
                                continue;
                            int nj = j;
                            if (k == x)
                                nj = 1;
                            ndp[i | 1 << k, nj] += dp[i, j];
                        }
            dp = ndp;
        }

        for (int i = 0; i < 1 << 7; i++)
        {
            dp[i, 0] += dp[i, 1];
            dp[i, 1] = 0;
        }

        foreach (int x in Fun(m - 1))
        {
            var ndp = new int[1 << 7, 2];
            for (int i = 0; i < 1 << 7; i++)
                for (int j = 0; j < 2; j++)
                    for (int k = 0; k < 7; k++)
                        if ((i >> k & 1) == 0)
                        {
                            if (j == 0 && k > x)
                                continue;
                            int nj = j;
                            if (k == x)
                                nj = 1;
                            ndp[i | 1 << k, nj] += dp[i, j];
                        }
            dp = ndp;
        }

        int ans = 0;
        for (int i = 0; i < 1 << 7; i++)
            for (int j = 0; j < 2; j++)
                ans += dp[i, j];

        Write(ans);
    }

    #region Main

    protected static TextReader reader;
    protected static TextWriter writer;
    static void Main()
    {
#if DEBUG
        reader = new StreamReader("..\\..\\input.txt");
        //reader = new StreamReader(Console.OpenStandardInput());
        writer = Console.Out;
        //writer = new StreamWriter("..\\..\\output.txt");
#else
        reader = new StreamReader(Console.OpenStandardInput());
        writer = new StreamWriter(Console.OpenStandardOutput(),Encoding.ASCII);
        //reader = new StreamReader("input.txt");
        //writer = new StreamWriter("output.txt");
#endif
        try
        {
            new Solver().Solve();
            //var thread = new Thread(new Solver().Solve, 1024 * 1024 * 128);
            //thread.Start();
            //thread.Join();
        }
        catch (Exception ex)
        {
#if DEBUG
            Console.WriteLine(ex);
#else
            throw;
#endif
        }
        reader.Close();
        writer.Close();
    }

    #endregion

    #region Read / Write
    private static Queue<string> currentLineTokens = new Queue<string>();
    private static string[] ReadAndSplitLine() { return reader.ReadLine().Split(new[] { ' ', '\t', }, StringSplitOptions.RemoveEmptyEntries); }
    public static string ReadToken() { while (currentLineTokens.Count == 0)currentLineTokens = new Queue<string>(ReadAndSplitLine()); return currentLineTokens.Dequeue(); }
    public static int ReadInt() { return int.Parse(ReadToken()); }
    public static long ReadLong() { return long.Parse(ReadToken()); }
    public static double ReadDouble() { return double.Parse(ReadToken(), CultureInfo.InvariantCulture); }
    public static int[] ReadIntArray() { return ReadAndSplitLine().Select(int.Parse).ToArray(); }
    public static long[] ReadLongArray() { return ReadAndSplitLine().Select(long.Parse).ToArray(); }
    public static double[] ReadDoubleArray() { return ReadAndSplitLine().Select(s => double.Parse(s, CultureInfo.InvariantCulture)).ToArray(); }
    public static int[][] ReadIntMatrix(int numberOfRows) { int[][] matrix = new int[numberOfRows][]; for (int i = 0; i < numberOfRows; i++)matrix[i] = ReadIntArray(); return matrix; }
    public static int[][] ReadAndTransposeIntMatrix(int numberOfRows)
    {
        int[][] matrix = ReadIntMatrix(numberOfRows); int[][] ret = new int[matrix[0].Length][];
        for (int i = 0; i < ret.Length; i++) { ret[i] = new int[numberOfRows]; for (int j = 0; j < numberOfRows; j++)ret[i][j] = matrix[j][i]; } return ret;
    }
    public static string[] ReadLines(int quantity) { string[] lines = new string[quantity]; for (int i = 0; i < quantity; i++)lines[i] = reader.ReadLine().Trim(); return lines; }
    public static void WriteArray<T>(IEnumerable<T> array) { writer.WriteLine(string.Join(" ", array)); }
    public static void Write(params object[] array) { WriteArray(array); }
    public static void WriteLines<T>(IEnumerable<T> array) { foreach (var a in array)writer.WriteLine(a); }
    private class SDictionary<TKey, TValue> : Dictionary<TKey, TValue>
    {
        public new TValue this[TKey key]
        {
            get { return ContainsKey(key) ? base[key] : default(TValue); }
            set { base[key] = value; }
        }
    }
    private static T[] Init<T>(int size) where T : new() { var ret = new T[size]; for (int i = 0; i < size; i++)ret[i] = new T(); return ret; }
    #endregion
}