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

namespace Codeforces0710B
{
    class Program
    {

        static bool isprime(long a)
        {

            for(long i = 2;i<=Math.Sqrt(a);i++)
            {
                if (a % i == 0)
                    return false;
            }

            return true;
        }
        static void Main(string[] args)
        {

            int testCases;
            testCases = int.Parse(Console.ReadLine());

            while (testCases-- > 0)
            {

                string read;
                read = Console.ReadLine();
                long a = long.Parse(read.Split(' ').ToList()[0]);
                long b = long.Parse(read.Split(' ').ToList()[1]);

                bool flag = true;

                if (a % 2 == 1 && b % 2 == 1)
                {
                    flag = false;
                }

                if (a % 2 == 0 && b % 2 == 0)
                {
                    flag = false;
                }

                if (a - b > 1)
                {
                    flag = false;
                }

                if(flag)
                {
                    flag = isprime(a + b);
                }

                if(flag)
                {
                    Console.WriteLine("YES");
                }
                else
                {
                    Console.WriteLine("NO");
                }

            }
        }
    }
}


using System;

public sealed class Program {

  const Int64 Mod = 1000000007;

  static void Add(ref Int64 cur, Int64 add) {
    cur = (cur + add) % Mod;
  }

  public Program () {
    Int32[] token = ReadArray();
    Int32 n = token[0], cap = token[1], i, cnt50 = 0, cnt100 = 0, a, b, c, d;
    token = ReadArray();
    Array.Sort(token);
    if (cap < 50 || cap < token[n - 1] || n != 1 && cap < token[0] + token[1]) {
      Console.WriteLine(-1);
      Console.WriteLine('0');
      return;
    }
    foreach (Int32 body in token) {
      if (body == 50) {
        ++cnt50;
      } else {
        ++cnt100;
      }
    }
    Int64[,] binomial = new Int64[n + 1, n + 1];
    for (i = 0; i <= n; ++i) {
      binomial[i, 0] = binomial[i, i] = 1;
    }
    for (a = 2; a <= n; ++a) {
      for (b = 1; b < a; ++b) {
        binomial[a, b] = (binomial[a - 1, b] + binomial[a - 1, b - 1]) % Mod;
      }
    }
    Int64[, ,] dp = new Int64[2, cnt50 + 1, cnt100 + 1];
    dp[0, cnt50, cnt100] = 1;
    for (i = 0; ; ++i) {
      if (i % 2 != 0 && dp[i % 2, cnt50, cnt100] != 0) {
        Console.WriteLine(i);
        Console.WriteLine(dp[i % 2, cnt50, cnt100]);
        return;
      }
      for (a = 0; a <= cnt50; ++a) {
        for (b = 0; b <= cnt100; ++b) {
          if (dp[i % 2, a, b] != 0) {
            for (c = 0; c <= a; ++c) {
              for (d = 0; d <= b && c * 50 + d * 100 <= cap; ++d) {
                if (c + d != 0) {
                  Add(ref dp[1 - i % 2, cnt50 - (a - c), cnt100 - (b - d)], dp[i % 2, a, b] * binomial[a, c] % Mod * binomial[b, d] % Mod);
                }
              }
            }
          }
        }
      }
    }
  }

  // stuff cutline

  public static void Main() {
#if DEBUG
    Console.SetIn(new System.IO.StreamReader("..\\..\\in.txt"));
#endif
    var root = new Program();
    Console.Out.Flush();
  }

  static Int32 ReadInt() {
    Boolean neg = false;
    Int32 ch, ans = 0;
    do {
      ch = Console.Read();
      neg |= ch == (Int32)'-';
    } while (!Char.IsDigit((Char)ch));
    do {
      ans = ans * 10 + (ch & 0xf);
      ch = Console.Read();
    } while (Char.IsDigit((Char)ch));
    return neg ? -ans : ans;
  }

  static Int32[] ReadArray() {
    return Array.ConvertAll<String, Int32>(Console.ReadLine().Split(), Int32.Parse);
  }

}


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

namespace Trenya260619
{
    class Input
    {
        private static IEnumerator<string> _getinput()
        {
            while (true)
                foreach (string s in Console.ReadLine().Split().Where(x => x.Length > 0))
                    yield return s;
        }

        private IEnumerator<string> input = _getinput();

        public string GetString()
        {
            input.MoveNext();
            return input.Current;
        }

        public int GetInt() { return int.Parse(GetString()); }
        public long GetLong() { return long.Parse(GetString()); }
        public double GetDouble() { return double.Parse(GetString()); }
    }

    class Program
    {
        static Input csin = new Input();

        static void Main(string[] args)
        {
            int n = csin.GetInt();
            long k = csin.GetLong();
            List<int> s = csin.GetString().Select(x => (int)(x - 'a')).ToList();
            s.Add(26);

            long[,] d = new long[n + 1, n + 1]; // i - length, j - first index

            d[0, n] = 1;

            bool[] ex = new bool[27];

            for (int len = 1; len <= n; len++)
                for (int start = 0; start < n; start++)
                {
                    for (int i = 0; i < 27; i++) ex[i] = false;

                    for (int j = start + 1; j <= n; j++)
                    {
                        if (ex[s[j]]) continue;
                        ex[s[j]] = true;
                        d[len, start] += d[len - 1, j];
                    }
                }

            long[] lenans = new long[n + 1];
            for (int i = 0; i <= n; i++)
            {
                for (int j = 0; j < 27; j++) ex[j] = false;

                for (int j = 0; j <= n; j++)
                {
                    if (ex[s[j]]) continue;

                    lenans[i] += d[i, j];
                    ex[s[j]] = true;
                }
            }

            long ans = 0;

            for (int i = n; i >= 0 && k > 0; i--)
            {
                long curr = Math.Min(k, lenans[i]);
                k -= curr;
                ans += curr * (n - i);
            }

            if (k > 0) ans = -1;

            Console.WriteLine(ans);
            //Console.ReadKey();
        }

    }
}


using System;
using System.Linq;
using CompLib.Util;

public class Program
{
    int N;
    long K;
    string S;
    public void Solve()
    {
        var sc = new Scanner();
        N = sc.NextInt();
        K = sc.NextLong();
        S = sc.Next();

        // iまで見た、スキップj個 最後文字
        var dp = new long[N + 1, N + 1, 27];
        dp[0, 0, 26] = 1;
        for (int i = 0; i < N; i++)
        {
            for (int j = 0; j <= i; j++)
            {

                for (int c = 0; c <= 26; c++)
                {
                    // s_iを使う
                    dp[i + 1, j, S[i] - 'a'] += dp[i, j, c];

                    // 使わない
                    if (S[i] - 'a' != c) dp[i + 1, j + 1, c] += dp[i, j, c];
                }
            }
        }

        long[] cnt = new long[N + 1];
        for (int i = 0; i <= N; i++)
        {
            for (int c = 0; c <= 26; c++)
            {
                cnt[i] += dp[N, i, c];
            }
        }

        long ans = 0;
        for (int i = 0; i <= N && K > 0; i++)
        {
            // Console.WriteLine($"{i} {cnt[i]} {K}");
            if (cnt[i] < K)
            {
                ans += cnt[i] * i;
                K -= cnt[i];
            }
            else
            {
                ans += i * K;
                K = 0;
            }
        }

        if (K > 0)
        {
            Console.WriteLine("-1");
            return;
        }

        Console.WriteLine(ans);
    }

    public static void Main(string[] args) => new Program().Solve();
}

namespace CompLib.Util
{
    using System;
    using System.Linq;

    class Scanner
    {
        private string[] _line;
        private int _index;
        private const char Separator = ' ';

        public Scanner()
        {
            _line = new string[0];
            _index = 0;
        }

        public string Next()
        {
            if (_index >= _line.Length)
            {
                string s;
                do
                {
                    s = Console.ReadLine();
                } while (s.Length == 0);

                _line = s.Split(Separator);
                _index = 0;
            }

            return _line[_index++];
        }

        public string ReadLine()
        {
            _index = _line.Length;
            return Console.ReadLine();
        }

        public int NextInt() => int.Parse(Next());
        public long NextLong() => long.Parse(Next());
        public double NextDouble() => double.Parse(Next());
        public decimal NextDecimal() => decimal.Parse(Next());
        public char NextChar() => Next()[0];
        public char[] NextCharArray() => Next().ToCharArray();

        public string[] Array()
        {
            string s = Console.ReadLine();
            _line = s.Length == 0 ? new string[0] : s.Split(Separator);
            _index = _line.Length;
            return _line;
        }

        public int[] IntArray() => Array().Select(int.Parse).ToArray();
        public long[] LongArray() => Array().Select(long.Parse).ToArray();
        public double[] DoubleArray() => Array().Select(double.Parse).ToArray();
        public decimal[] DecimalArray() => Array().Select(decimal.Parse).ToArray();
    }
}


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

namespace C1
{
    class Program
    {
        static void Main(string[] args)
        {
            string str,str1="",ch="",sl="/",ru=".ru";
            int num = 0;
            str=Console.ReadLine();
                if (str[0] == 'h')
                    {
                    str1 = "http://";
                        for (int i = 4; i < str.Length; i++)
                            {
                                if (i != 4 && str[i] == 'r' && str[i + 1] == 'u') { num = i; break; }
                                str1 += str[i];
                                }
                    str1 += ru;
                    num += 2;
                        if (num == str.Length) Console.WriteLine(str1);
                            else
                            {
                            str1 += sl;
                                for (int i = num; i < str.Length; i++)
                                str1 += str[i];
                            Console.WriteLine(str1);
                }
            }

                else
                {
                str1 = "ftp://";

                    for (int i = 3; i < str.Length; i++)
                    {
                        if (i != 3 && str[i] == 'r' && str[i + 1] == 'u') { num = i; break; }
                    str1 += str[i];
                    }
                str1 += ru;
                num += 2;
                    if (num == str.Length) Console.WriteLine(str1);
                        else
                        {
                        str1 += sl;
                            for (int i = num; i < str.Length; i++)
                            str1 += str[i];
                Console.WriteLine(str1);
            }
            }

        }
    }
}


using System;

class Program
{
    static void Main(string[] args)
    {
        string input = Console.ReadLine();
        string output = "";
        int ind = input.IndexOf("ru");
        if (input[0].Equals('f'))
        {
            output += "ftp://";
            if (ind == 3) ind = input.IndexOf("ru", 5);
            output += input.Substring(3, ind - 3);
        }
        else
        {
            output += "http://";
            if (ind == 4) ind = input.IndexOf("ru", 6);
            output += input.Substring(4, ind - 4);
        }
        output += ".ru";
        if (ind + 2 != input.Length)
            output += "/" + input.Substring(ind + 2, input.Length - (ind + 2));
        Console.WriteLine(output);
        Console.ReadLine();
    }
}


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

namespace Codeforces
{
    class Program
    {
        static void Main(string[] args)
        {

            string str = Console.ReadLine();

            int countUnSimilar = 0;
            for (int i = 0; i < str.Length / 2; i++)
            {
                if (str[i] != str[str.Length - i - 1])
                    countUnSimilar++;
            }

            if (countUnSimilar == 1||(countUnSimilar==0&&str.Length%2!=0))
                Console.WriteLine("YES");
            else
                Console.WriteLine("NO");

        }

    }
}


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

namespace Main_Problem_Template
{
    class Program
    {

        const string input = "input.txt";
        const string output = "output.txt";

        static void Main(string[] args)
        {
            List<int> inputInt = new List<int>();
            List<char> inputChar = new List<char>();

            //ReadData(input, inputInt, inputChar);
            ReadConsole(inputInt, inputChar);
            string outputS = F1(inputChar);
            WriteConsole(inputInt, inputChar, outputS);
            //WriteData(output,inputInt,inputChar,outputS);

        }

        static string F1(List<char> inputChar)
        {
            int fails = 0;
            int n = inputChar.Count();
            bool even;
            if (n % 2 == 0)
            {
                even = true;
            }
            else
            {
                even = false;
            }

            if (even)
            {
                for (int i = 0; i < n/2; i++)
                {
                    if (inputChar[i] != inputChar[n-1 - i])
                    {
                        fails++;
                    }
                }
            }
            else {
                for (int i = 0; i < (n-1)/2; i++)
                {
                    if (inputChar[i] != inputChar[n-1 - i])
                    {
                        fails++;
                    }
                }
            }

            if (fails == 1 && even)
            {
                return "YES";
            }
            else if (fails <2 && !even)
            {
                return "YES";
            }
            else
            {
                return "NO";
            }
        }

        static void ReadConsole(List<int> inputInt, List<char> inputChar)
        {
            string line = Console.ReadLine();
            inputChar.AddRange(line);
        }

        static void WriteConsole(List<int> outputInt, List<char> outputChar, string outputS)
        {
            Console.WriteLine(outputS);
        }

        static void ReadData(string file, List<int> inputInt, List<char> inputChar)
        {
            string line;

            using (StreamReader reader = new StreamReader(@file))
            {
                //k = int.Parse(reader.ReadLine());
                line = reader.ReadLine();
                //string[] parts = line.Split(' ');
                for (int i = 0; i < line.Length; i++)
                {
                    inputChar.Add(line[i]);
                }

            }
        }

        static void WriteData(string fv, List<int> outputInt, List<char> outputChar,string outputS)
        {
            using (var file = new System.IO.StreamWriter(fv, false))
            {
                //file.Write();
                //file.WriteLine();
                //file.WriteLine(count);
                /*
                foreach (char x in outputChar)
                {
                    file.Write(x);
                    Console.Write(x);
                }
                */
                file.Write(outputS);
                Console.Write(outputS);
            }
            Console.WriteLine();
        }

    }
}


#if DEBUG
using System.Reflection;
using System.Threading.Tasks;
#endif

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

#if DEBUG
using System.Diagnostics;
#endif

namespace ed29b
{
    class Program
    {
        static string _inputFilename = "input.txt";
        static string _outputFilename = "output.txt";
        static bool _useFileInput = false;
        const string _delim = "!";

        static void Main(string[] args)
        {
            StreamWriter file = null;
#if DEBUG
            var testNumber = 0;
            var timer = new Stopwatch();
            foreach (var test in GetTests())
            {

                timer.Start();

                var defaultColor = Console.ForegroundColor;
                Console.ForegroundColor = ConsoleColor.DarkYellow;
                Console.WriteLine($"<!-- TEST #{testNumber} -->");
                Console.ForegroundColor = defaultColor;
                Console.SetIn(test);

#else
            if (_useFileInput)
            {
                Console.SetIn(File.OpenText(_inputFilename));
                file = new StreamWriter(_outputFilename);
                Console.SetOut(file);
            }
#endif

            try
            {
                Solution();
            }
            finally
            {
                if (_useFileInput)
                {
                    file.Close();
                }
            }

#if DEBUG
                timer.Stop();

                Console.ForegroundColor = ConsoleColor.DarkYellow;
                Console.WriteLine($"<!-- TEST #{testNumber} FINISHED IN {timer.Elapsed.ToString(@"ss\:fff")}-->");
                Console.ForegroundColor = defaultColor;

                timer.Reset();
                testNumber++;
            }
#endif
        }

        static void Solution()
        {
            #region SOLUTION
            var n = ReadInt();
            var a = ReadIntArray();

            Array.Sort(a);

            var min = int.MaxValue;
            for (int i = 0; i < 2 * n; i++)
            {
                for (int j = i + 1; j < 2 * n; j++)
                {
                    var sum = 0;

                    var k1 = 0;
                    var k2 = 0;
                    while (true)
                    {
                        if (k1 == i || k1 == j)
                        {
                            k1++;
                            continue;
                        }

                        if (k2 <= k1)
                        {
                            k2 = k1 + 1;
                        }

                        if (k2 == i || k2 == j)
                        {
                            k2++;
                            continue;
                        }

                        if (k2 >= 2 * n)
                        {
                            break;
                        }

                        sum += (a[k2] - a[k1]);
                        k1 = k2 + 1;
                    }

                    if (sum < min)
                    {
                        min = sum;
                    }
                }
            }

            Console.WriteLine(min);
            //var n = readInt();
            //var m = readInt();

            //var a = readIntArray();
            //var b = readIntArray();
            #endregion
        }

        static int ReadInt()
        {
            return int.Parse(Console.ReadLine());
        }

        static long ReadLong()
        {
            return long.Parse(Console.ReadLine());
        }

        static int[] ReadIntArray()
        {
            return Console.ReadLine().Split(' ').Where(i => !string.IsNullOrEmpty(i)).Select(i => int.Parse(i)).ToArray();
        }

        static long[] ReadLongArray()
        {
            return Console.ReadLine().Split(' ').Where(i => !string.IsNullOrEmpty(i)).Select(i => long.Parse(i)).ToArray();
        }

#if DEBUG
        static IEnumerable<TextReader> GetTests()
        {
            var tests = new List<string>();
            var resName = Assembly.GetCallingAssembly().GetManifestResourceNames()[0];
            using (var resource = new StreamReader(Assembly.GetCallingAssembly().GetManifestResourceStream(resName)))
            {
                while (true)
                {
                    var nextText = new StringBuilder();
                    var endOfFile = false;
                    while (true)
                    {
                        var line = resource.ReadLine();

                        endOfFile = line == null;
                        if (endOfFile)
                        {
                            break;
                        }

                        if (line.Equals(_delim, StringComparison.Ordinal))
                        {
                            break;
                        }

                        nextText.AppendLine(line);
                    }

                    yield return new StringReader(nextText.ToString());

                    if (endOfFile)
                    {
                        break;
                    }
                }
            }
        }
#endif
    }
}


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

namespace CodeForces
{
   class B
   {
      static void Main(string[] args)
      {
         int n = int.Parse(Console.ReadLine());
         List<int> a = new List<int>();
         string[] token = Console.ReadLine().Split();
         for(int i=0;i<2*n;i++)
         {
         	a.Add(int.Parse(token[i]));
         }
         a.Sort();
         int min = int.MaxValue;
        for (int i = 0; i < a.Count; i++)
        {
          for (int j = i + 1; j < a.Count; j++)
          {
              int last = -1;
              int sum = 0;
              for (int k = 0; k < a.Count; k++)
              {
                  if (k == i || k == j)
                      continue;

                  if (last == -1)
                      last = a[k];
                  else
                  {
                      sum += a[k] - last;
                      last = -1;
                  }

              }
              if(sum<min)
              {
                 min = sum;
              }
          }
        }
        Console.WriteLine(min);
      }
  }
}


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.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.Linq;

namespace CodeForce
{
    internal class Quserty
    {
        private static void Main(string[] args)
        {
            var input = Console.ReadLine();
            var inps = input.Split(' ');
            var length = int.Parse(inps.First());
            var diameter = int.Parse(inps[1]);

            input = Console.ReadLine();
            var array = input.Split(' ').Select(int.Parse).OrderBy(it => it).ToArray();
            var max = array[array.Length - 1];

            var isInSet = new int[max + 1];
            for (var i = 0; i < array.Length; i++)
            {
                var el = array[i];
                isInSet[el] += 1;
            }

            for (var i = 1; i < isInSet.Length; i++)
            {
                isInSet[i] = isInSet[i - 1] + isInSet[i];
            }

            var result = int.MaxValue;

            for (var i = 0;; i++)
            {
                var leftElement = array[i];
                var rightElement = leftElement + diameter;
                if (rightElement > max)
                {
                    rightElement = max;
                }

                var diff = isInSet[rightElement] - isInSet[leftElement - 1];
                var newResult = array.Length - diff;
                result = Math.Min(result, newResult);

                if (rightElement == max)
                {
                    break;
                }
            }

            Console.WriteLine(result);
        }
    }
}


using System;
using System.Linq;

namespace CSharp
{
    class _940A
    {
        public static void Main()
        {
            var tokens = Console.ReadLine().Split();

            int n = int.Parse(tokens[0]);
            int d = int.Parse(tokens[1]);

            var x = Console.ReadLine().Split().Select(token => int.Parse(token)).ToArray();
            Array.Sort(x);

            Console.WriteLine(n - Enumerable.Range(0, n).Max(r => Enumerable.Range(0, r + 1).Where(l => x[r] - x[l] <= d).Max(l => r + 1 - l)));
        }
    }
}


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

public class Solver
{
    public object Solve()
    {
        int n = ReadInt();
        int m = ReadInt();

        int[] id = new int[m];
        int?[] status = new int?[n];

        int cand = -1;
        for (int i = 0; i < m; i++)
        {
            bool action = ReadToken() == "+";
            id[i] = ReadInt() - 1;
            if (status[id[i]] == null)
            {
                status[id[i]] = action ? 1 : 2;
                if (!action)
                    cand = id[i];
            }
        }
        if (cand == -1)
            cand = id[0];

        var set = new SortedSet<int>(Enumerable.Range(1, n).Where(i => status[i - 1] == null));
        bool[] on = Enumerable.Range(0, n).Select(i => status[i] == 2).ToArray();
        int onCount = status.Count(s => s == 2);
        int step;
        for (step = 0; step < m; step++)
        {
            if (id[step] == cand)
            {
                if (on[cand] && onCount > 1)
                    break;
            }
            else if (!on[cand])
                    break;
            on[id[step]] = !on[id[step]];
            if (on[id[step]])
                onCount++;
            else
                onCount--;
        }
        if (step == m)
            set.Add(cand + 1);

        writer.WriteLine(set.Count);
        WriteArray(set);

        return null;
    }

    #region Main

    protected static TextReader reader;
    protected static TextWriter writer;

    static void Main()
    {
#if DEBUG
        reader = new StreamReader("..\\..\\input.txt");
        writer = Console.Out;
        //writer = new StreamWriter("..\\..\\output.txt");
#else
        reader = Console.In;
        writer = Console.Out;
#endif
        try
        {
            object result = new Solver().Solve();
            if (result != null)
            {
                writer.WriteLine(result);
            }
        }
        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()
    {
        if (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 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));
    }

    #endregion
}


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

namespace ProblemSets
{
    using System;
    using System.Collections.Generic;
    using System.Collections;
    using System.Linq;
    using System.Text;

    namespace LongPath
    {
        public class Problem420b
        {
            public static void Main(string[] args)
            {
                var input = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
                var numberOfPeople = input[0];
                var numberOfMessage = input[1];

                bool[] seen = new bool[100000 + 1];
                int leaderId = -1;
                bool leaderOnline = false;
                var peopleOnline = 0;

                for (int i = 0; i < numberOfMessage; i++)
                {
                    var status = Console.ReadLine().Split(' ');
                    var symbol = status[0][0];
                    var id = int.Parse(status[1]);

                    if (symbol == '+')
                    {

                            if(i== 0)
                            {
                               leaderId = id;
                               leaderOnline = true;
                            }

                        else // there is a leader
                        {
                            if (leaderOnline)
                            {
                                //do nothing
                            }
                            else
                            {
                                if (leaderId == id)
                                {
                                    leaderOnline = true;
                                }
                                else
                                {
                                    leaderId = -1;
                                    leaderOnline = false;
                                }
                            }
                        }
                        peopleOnline++;
                    }

                    if (symbol == '-')
                    {
                        if (!seen[id])
                        {
                            if (peopleOnline == 0)
                            {
                                leaderId = id;
                                leaderOnline = false;
                            }
                            else
                            {
                                leaderId = -1;
                                leaderOnline = false;
                            }
                        }

                        else
                        {
                            peopleOnline = Math.Max(--peopleOnline, 0);
                            if (leaderId == -1)
                            {
                                //if there is no leader, do nothing
                            }
                            else
                            {
                                if (leaderId == id)
                                {
                                    if (peopleOnline > 0)
                                    {
                                        leaderId = -1;
                                        leaderOnline = false;
                                    }
                                    else
                                    {
                                        leaderOnline = false;
                                    }
                                }
                                else
                                {
                                    if (!leaderOnline)
                                    {
                                        leaderId = -1;
                                        leaderOnline = false;
                                    }
                                }
                            }
                        }

                    }
                    seen[id] = true;
                }

                var leaders = new ArrayList();
                for (int i = 1; i <= numberOfPeople; i++)
                {
                    if (!seen[i]) leaders.Add(i);
                    else if (leaderId == i) leaders.Add(i);
                }

                var numberOfLeader = leaders.Count;
                Console.WriteLine(numberOfLeader);

                foreach (var leader in leaders)
                {
                    Console.Write(leader);
                    Console.Write(" ");
                }

            }
        }
    }
}


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

namespace example
{
    class Program
    {
        public static void Main(string[] args)
        {
            var line = Console.ReadLine().Split();
            int[] array = line.Select(p => int.Parse(p)).ToArray();
            Array.Sort(array);
            int a = array[0];
            int b = array[1];
            int c = array[2];
            if(Can(a,b,c))
                Console.WriteLine("YES");
            else Console.WriteLine("NO");
        }

        public static bool Can(int a, int b, int c)
        {
            if (a == 1)
                return true;
            if (a == 2 && (b == 2 ||(b == 4 && c == 4)))
                return true;
            if (a == 3 && b == 3 && c == 3)
                return true;

            return false;
        }
    }
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Runtime.CompilerServices;
using System.Text;
using System.Diagnostics;
using System.Numerics;
using static System.Console;
using static System.Convert;
using static System.Math;
using static Template;
using Pi = Pair<int, int>;

class Solver
{
    public void Solve(Scanner sc)
    {
        var K = sc.ArrInt.Select((v, idx) => (v: v, idx: idx)).ToArray();
        Array.Sort(K, (a, b) => a.v - b.v);
        if (K[0].v == 1) Fail("YES");
        if (K.Select(k => k.v).Count(a => a <= 2) >= 2) Fail("YES");
        if (K.Select(k => k.v).All(v => v == 3)) Fail("YES");
        if (K[0].v == 2 && K[1].v == 4 && K[2].v == 4) Fail("YES");
        Console.WriteLine("NO");
    }
}

#region Template
public static class Template
{
    static void Main(string[] args)
    {
        Console.SetOut(new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false });
        new Solver().Solve(new Scanner());
        Console.Out.Flush();
    }
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public static bool chmin<T>(ref T a, T b) where T : IComparable<T> { if (a.CompareTo(b) > 0) { a = b; return true; } return false; }
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public static bool chmax<T>(ref T a, T b) where T : IComparable<T> { if (a.CompareTo(b) < 0) { a = b; return true; } return false; }
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public static void swap<T>(ref T a, ref T b) { var t = b; b = a; a = t; }
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public static void swap<T>(this IList<T> A, int i, int j) { var t = A[i]; A[i] = A[j]; A[j] = t; }
    public static T[] Create<T>(int n, Func<T> f) { var rt = new T[n]; for (var i = 0; i < rt.Length; ++i) rt[i] = f(); return rt; }
    public static T[] Create<T>(int n, Func<int, T> f) { var rt = new T[n]; for (var i = 0; i < rt.Length; ++i) rt[i] = f(i); return rt; }
    public static IEnumerable<T> Shuffle<T>(this IEnumerable<T> A) => A.OrderBy(v => Guid.NewGuid());
    public static int CompareTo<T>(this T[] A, T[] B, Comparison<T> cmp = null) { cmp = cmp ?? Comparer<T>.Default.Compare; for (var i = 0; i < Min(A.Length, B.Length); i++) { int c = cmp(A[i], B[i]); if (c > 0) return 1; else if (c < 0) return -1; } if (A.Length == B.Length) return 0; if (A.Length > B.Length) return 1; else return -1; }
    public static int MaxElement<T>(this IList<T> A, Comparison<T> cmp = null) { cmp = cmp ?? Comparer<T>.Default.Compare; T max = A[0]; int rt = 0; for (int i = 1; i < A.Count; i++) if (cmp(max, A[i]) < 0) { max = A[i]; rt = i; } return rt; }
    public static T PopBack<T>(this List<T> A) { var v = A[A.Count - 1]; A.RemoveAt(A.Count - 1); return v; }
    public static void Fail<T>(T s) { Console.WriteLine(s); Console.Out.Close(); Environment.Exit(0); }
}
public class Scanner
{
    public string Str => Console.ReadLine().Trim();
    public int Int => int.Parse(Str);
    public long Long => long.Parse(Str);
    public double Double => double.Parse(Str);
    public int[] ArrInt => Str.Split(' ').Select(int.Parse).ToArray();
    public long[] ArrLong => Str.Split(' ').Select(long.Parse).ToArray();
    public char[][] Grid(int n) => Create(n, () => Str.ToCharArray());
    public int[] ArrInt1D(int n) => Create(n, () => Int);
    public long[] ArrLong1D(int n) => Create(n, () => Long);
    public int[][] ArrInt2D(int n) => Create(n, () => ArrInt);
    public long[][] ArrLong2D(int n) => Create(n, () => ArrLong);
    private Queue<string> q = new Queue<string>();
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public T Next<T>() { if (q.Count == 0) foreach (var item in Str.Split(' ')) q.Enqueue(item); return (T)Convert.ChangeType(q.Dequeue(), typeof(T)); }
    public void Make<T1>(out T1 v1) => v1 = Next<T1>();
    public void Make<T1, T2>(out T1 v1, out T2 v2) { v1 = Next<T1>(); v2 = Next<T2>(); }
    public void Make<T1, T2, T3>(out T1 v1, out T2 v2, out T3 v3) { Make(out v1, out v2); v3 = Next<T3>(); }
    public void Make<T1, T2, T3, T4>(out T1 v1, out T2 v2, out T3 v3, out T4 v4) { Make(out v1, out v2, out v3); v4 = Next<T4>(); }
    public void Make<T1, T2, T3, T4, T5>(out T1 v1, out T2 v2, out T3 v3, out T4 v4, out T5 v5) { Make(out v1, out v2, out v3, out v4); v5 = Next<T5>(); }
    public void Make<T1, T2, T3, T4, T5, T6>(out T1 v1, out T2 v2, out T3 v3, out T4 v4, out T5 v5, out T6 v6) { Make(out v1, out v2, out v3, out v4, out v5); v6 = Next<T6>(); }
    public void Make<T1, T2, T3, T4, T5, T6, T7>(out T1 v1, out T2 v2, out T3 v3, out T4 v4, out T5 v5, out T6 v6, out T7 v7) { Make(out v1, out v2, out v3, out v4, out v5, out v6); v7 = Next<T7>(); }
    //public (T1, T2) Make<T1, T2>() { Make(out T1 v1, out T2 v2); return (v1, v2); }
    //public (T1, T2, T3) Make<T1, T2, T3>() { Make(out T1 v1, out T2 v2, out T3 v3); return (v1, v2, v3); }
    //public (T1, T2, T3, T4) Make<T1, T2, T3, T4>() { Make(out T1 v1, out T2 v2, out T3 v3, out T4 v4); return (v1, v2, v3, v4); }
}
public class Pair<T1, T2> : IComparable<Pair<T1, T2>>
{
    public T1 v1;
    public T2 v2;
    public Pair() { }
    public Pair(T1 v1, T2 v2)
    { this.v1 = v1; this.v2 = v2; }

    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public int CompareTo(Pair<T1, T2> p)
    {
        var c = Comparer<T1>.Default.Compare(v1, p.v1);
        if (c == 0)
            c = Comparer<T2>.Default.Compare(v2, p.v2);
        return c;
    }
    public override string ToString() => $"{v1.ToString()} {v2.ToString()}";
    public void Deconstruct(out T1 a, out T2 b) { a = v1; b = v2; }
}

public class Pair<T1, T2, T3> : Pair<T1, T2>, IComparable<Pair<T1, T2, T3>>
{
    public T3 v3;
    public Pair() : base() { }
    public Pair(T1 v1, T2 v2, T3 v3) : base(v1, v2)
    { this.v3 = v3; }

    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public int CompareTo(Pair<T1, T2, T3> p)
    {
        var c = base.CompareTo(p);
        if (c == 0)
            c = Comparer<T3>.Default.Compare(v3, p.v3);
        return c;
    }
    public override string ToString() => $"{base.ToString()} {v3.ToString()}";
    public void Deconstruct(out T1 a, out T2 b, out T3 c) { Deconstruct(out a, out b); c = v3; }
}
#endregion


using System;
using System.Linq;
using System.Collections.Generic;
using Debug = System.Diagnostics.Debug;
using StringBuilder = System.Text.StringBuilder;
using System.Numerics;
using Point = System.Numerics.Complex;
using Number = System.Int64;
namespace Program
{
    public class Solver
    {
        public void Solve()
        {
            var q = sc.Integer();
            var par = new int[500002];
            par[0] = -1;
            var dp = Enumerate(500002, x => new double[45]);
            for (int i = 1; i < 45; i++)
                dp[0][i] = 1.0;

            var ptr = 1;
            Action<int> recalc = null;
            recalc = v =>
              {
                  for (int h = 1; h < 40; h++)
                      dp[v][h] = 1.0;
                  var ps = new List<int>();
                  for (int h = 0; h <= 40; h++)
                  {
                      if (v == -1) break;
                      ps.Add(v);
                      v = par[v];
                  }
                  for (int i = ps.Count - 2; i > 0; i--)
                  {
                      var u = ps[i]; var h = i;
                      var p = ps[i + 1];
                      dp[p][h + 1] /= (dp[u][h] + 1) / 2;
                  }
                  for (int i = 0; i + 1 < ps.Count; i++)
                  {
                      var u = ps[i]; var h = i;
                      var p = ps[i + 1];
                      dp[p][h + 1] *= (dp[u][h] + 1) / 2;
                  }
              };
            for (int i = 0; i < q; i++)
            {
                if (sc.Integer() == 1)
                {
                    var p = sc.Integer() - 1;
                    par[ptr] = p;
                    recalc(ptr);
                    ptr++;

                }
                else
                {
                    var v = sc.Integer() - 1;
                    var ans = 0.0;
                    for (int h = 1; h < 40; h++)
                        ans += 1 - dp[v][h];
                    Debug.WriteLine(dp[v].AsJoinedString());
                    IO.Printer.Out.WriteLine(ans);

                }
            }
        }
        public IO.StreamScanner sc = new IO.StreamScanner(Console.OpenStandardInput());
        static T[] Enumerate<T>(int n, Func<int, T> f) { var a = new T[n]; for (int i = 0; i < n; ++i) a[i] = f(i); return a; }
        static public void Swap<T>(ref T a, ref T b) { var tmp = a; a = b; b = tmp; }
    }
}

#region main
static class Ex
{
    static public string AsString(this IEnumerable<char> ie) { return new string(System.Linq.Enumerable.ToArray(ie)); }
    static public string AsJoinedString<T>(this IEnumerable<T> ie, string st = " ") { return string.Join(st, ie); }
    static public void Main()
    {
        var solver = new Program.Solver();
        solver.Solve();
        Program.IO.Printer.Out.Flush();
    }
}
#endregion
#region Ex
namespace Program.IO
{
    using System.IO;
    using System.Text;
    using System.Globalization;
    public class Printer: StreamWriter
    {
        static Printer() { Out = new Printer(Console.OpenStandardOutput()) { AutoFlush = false }; }
        public static Printer Out { get; set; }
        public override IFormatProvider FormatProvider { get { return CultureInfo.InvariantCulture; } }
        public Printer(System.IO.Stream stream) : base(stream, new UTF8Encoding(false, true)) { }
        public Printer(System.IO.Stream stream, Encoding encoding) : base(stream, encoding) { }
        public void Write<T>(string format, T[] source) { base.Write(format, source.OfType<object>().ToArray()); }
        public void WriteLine<T>(string format, T[] source) { base.WriteLine(format, source.OfType<object>().ToArray()); }
    }
    public class StreamScanner
    {
        public StreamScanner(Stream stream) { str = stream; }
        public readonly Stream str;
        private readonly byte[] buf = new byte[1024];
        private int len, ptr;
        public bool isEof = false;
        public bool IsEndOfStream { get { return isEof; } }
        private byte read()
        {
            if (isEof) return 0;
            if (ptr >= len) { ptr = 0; if ((len = str.Read(buf, 0, 1024)) <= 0) { isEof = true; return 0; } }
            return buf[ptr++];
        }
        public char Char() { byte b = 0; do b = read(); while ((b < 33 || 126 < b) && !isEof); return (char)b; }

        public string Scan()
        {
            var sb = new StringBuilder();
            for (var b = Char(); b >= 33 && b <= 126; b = (char)read())
                sb.Append(b);
            return sb.ToString();
        }
        public string ScanLine()
        {
            var sb = new StringBuilder();
            for (var b = Char(); b != '\n'; b = (char)read())
                if (b == 0) break;
                else if (b != '\r') sb.Append(b);
            return sb.ToString();
        }
        public long Long()
        {
            if (isEof) return long.MinValue;
            long ret = 0; byte b = 0; var ng = false;
            do b = read();
            while (b != 0 && b != '-' && (b < '0' || '9' < b));
            if (b == 0) return long.MinValue;
            if (b == '-') { ng = true; b = read(); }
            for (; true; b = read())
            {
                if (b < '0' || '9' < b)
                    return ng ? -ret : ret;
                else ret = ret * 10 + b - '0';
            }
        }
        public int Integer() { return (isEof) ? int.MinValue : (int)Long(); }
        public double Double() { var s = Scan(); return s != "" ? double.Parse(s, CultureInfo.InvariantCulture) : double.NaN; }
        private T[] enumerate<T>(int n, Func<T> f)
        {
            var a = new T[n];
            for (int i = 0; i < n; ++i) a[i] = f();
            return a;
        }

        public char[] Char(int n) { return enumerate(n, Char); }
        public string[] Scan(int n) { return enumerate(n, Scan); }
        public double[] Double(int n) { return enumerate(n, Double); }
        public int[] Integer(int n) { return enumerate(n, Integer); }
        public long[] Long(int n) { return enumerate(n, Long); }
    }
}
#endregion


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

namespace codeforces
{
    class Program
    {

        static void Main(string[] args)
        {
            ulong n = Convert.ToUInt64(Console.ReadLine());
            ulong value = n % 2;
            if (value == 0)
                value = 2;
            Console.WriteLine(value);
        }
    }
}


using System;

namespace ForCodeForces
{
    class Program
    {
        static void Main(string[] args)
        {
            long n = long.Parse(Console.ReadLine());

            if (n % 2 == 0)
                Console.WriteLine(2);
            else
                Console.WriteLine(1);
        }
    }
}


using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using static System.Math;
public static class P
{
    public static void Main()
    {
        string cf = "codeforces";
        var k = long.Parse(Console.ReadLine());
        long[] counts = Enumerable.Repeat(1L, cf.Length).ToArray();
        int ind = 0;
        while (true)
        {
            if (k <= counts.Aggregate(1L, (x, y) => x * y)) break;
            counts[ind]++;
            ind = (ind + 1) % counts.Length;
        }
        Console.WriteLine(string.Join("", counts.SelectMany((count, i) => Enumerable.Repeat(cf[i], (int)count))));
    }
}


using System;
using System.Linq;

namespace TaskB
{
    class Program
    {
        static void Main(string[] args)
        {
            var p = long.Parse(Console.ReadLine());

            long ans = 1;
            var mas = new[] { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 };
            var i = 0;
            while (ans < p)
            {
                mas[i]++;

                ans = Calc(mas);

                i++;
                i %= 10;

            }

            var s = "codeforces";
            for (int j = 0; j < 10; j++)
            {
                for (int k = 0; k < mas[j]; k++)
                {
                    Console.Write(s[j]);
                }
            }
        }

        private static long Calc(int[] mas)
        {
            return mas.Aggregate<int, long>(1, (current, t) => current * t);
        }
    }
}


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

namespace Codeforces
{

    public class C
    {

        public static void Main(string[] args)
        {
            string[] token = Console.ReadLine().Split();

            int n = int.Parse(token[0]);
            int m = int.Parse(token[1]);
            long k = long.Parse(token[2]);
            int x = int.Parse(token[3]);
            int y = int.Parse(token[4]);

            int sTo = ((x-1)*m) + y;
            int sBo = ((n-x)*m) + y;

            if(k<m*n){
              int sQ = (sTo<=k)?1:0;
              Console.WriteLine(1 + " " + 0 + " " + sQ);
            }
            else if (n > 2)
            {
                int A = (n * m) - m;
                long KK = k - m;
                long mod = KK % A;
                long div = (KK - mod) / A;
                long max = 0;
             //   if( n>2){
                  max = (mod > 0) ? div + 1 : div;
                  long v = 1 + div;
                  long min = (v%2!=0)?(v-1)/2:v/2;

                  long sQ = div;

                  if(x==1){
                    sQ =(div%2!=0)?(div-1)/2:div/2;
                    sQ++;
                  }else if(x==n){
                    sQ =(div%2!=0)?(div+1)/2:div/2;
                  }

                //  Console.WriteLine(v);
                  if((v%2==0 && sBo-m<=mod && x!=n) || (v%2!=0 && sTo-m<=mod && x!=1)){
                      sQ++;
                  }

                  Console.WriteLine((max) + " " + (min) + " " + sQ);
               // }
            }
            else
            {
                long mod = k%(m*n);
                long min = (k - mod) / (m*n);
                long max = (mod > 0) ? min + 1 : min;
                long sQ = (sTo<=mod)?min+1:min;

                Console.WriteLine(max + " " + min + " " + sQ);
            }
        }
    }

}


using System;

namespace _758C
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] input = Console.ReadLine().Split(' ');
            long n = long.Parse(input[0]), m = long.Parse(input[1]), x = long.Parse(input[3]), y = long.Parse(input[4]),
                k = long.Parse(input[2]);
            long T = 0, periods = 0;
            if (n > 2) T = m * (2 * n - 2);
            else T = m * n;
            if (T > 0)
            {
                periods = k / T;
                k = k % T;
            }
            long[,] matrix = new long[n, m];
            long min = long.MaxValue, max = 0;
            for (int i = 0; i < n; i++)
                for (int j = 0; j < m; j++)
                {
                    matrix[i, j] = periods * ((i == 0 || i == n - 1) ? 1 : 2);
                    if (k > 0)
                    {
                        matrix[i, j]++;
                        k--;
                    }
                }
            for (int i = (int)n - 2; i >= 0; i--)
                for (int j = 0; j < m; j++)
                {
                    if (k > 0)
                    {
                        matrix[i, j]++;
                        k--;
                    }
                }
            for (int i = 0; i < n; i++)
                for (int j = 0; j < m; j++)
                {
                    if (matrix[i, j] < min) min = matrix[i, j];
                    if (matrix[i, j] > max) max = matrix[i, j];
                }
            Console.WriteLine(max + " " + min + " " + matrix[x - 1, y - 1]);
        }
    }
}


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

class Program
{
    private static bool IsSimple(int x)
    {
        if ((x & 1) == 0) return x == 2;

        int end = (int)Math.Sqrt(x);
        for (int i = 3; i <= end; i += 2)
            if (x % i == 0)
                return false;

        return true;
    }

    private static int Solve(int n)
    {
        if (IsSimple(n)) return 1;
        if (n % 2 == 0) return 2;

        if (IsSimple(n - 2))
            return 2;

        return 3;
    }

    static void Main(string[] args)
    {
        Console.WriteLine(Solve(RI()));
    }

    private const int Mod = 1000000000 + 7;

    #region Data Read
    private static char ReadSign()
    {
        while (true)
        {
            int ans = consoleReader.Read();
            if (ans == '+' || ans == '-' || ans == '?')
                return (char)ans;
        }
    }

    private static long GCD(long a, long b)
    {
        if (a % b == 0) return b;
        return GCD(b, a % b);
    }

    private static List<int>[] ReadGraph(int n, int m)
    {
        List<int>[] g = new List<int>[n];
        for (int i = 0; i < g.Length; i++) g[i] = new List<int>();
        for (int i = 0; i < m; i++)
        {
            int a = RI() - 1;
            int b = RI() - 1;

            g[a].Add(b);
            g[b].Add(a);
        }

        return g;
    }

    private static int[,] ReadGraphAsMatrix(int n, int m)
    {
        int[,] matrix = new int[n + 1, n + 1];
        for (int i = 0; i < m; i++)
        {
            int a = RI();
            int b = RI();
            matrix[a, b] = matrix[b, a] = 1;
        }

        return matrix;
    }

    private static void Sort(ref int a, ref int b)
    {
        if (a > b) Swap(ref a, ref b);
    }

    private static void Swap(ref int a, ref int b)
    {
        int tmp = a;
        a = b;
        b = tmp;
    }

    private const int BufferSize = 1 << 16;
    private static StreamReader consoleReader;
    private static MemoryStream testData;

    private static int RI()
    {
        int ans = 0;
        int mul = 1;
        do
        {
            ans = consoleReader.Read();
            if (ans == -1)
                return 0;
            if (ans == '-') mul = -1;
        } while (ans < '0' || ans > '9');

        ans -= '0';
        while (true)
        {
            int chr = consoleReader.Read();
            if (chr < '0' || chr > '9')
                return ans * mul;
            ans = ans * 10 + chr - '0';
        }
    }

    private static ulong RUL()
    {
        ulong ans = 0;
        int chr;
        do
        {
            chr = consoleReader.Read();
            if (chr == -1)
                return 0;
        } while (chr < '0' || chr > '9');

        ans = (uint)(chr - '0');
        while (true)
        {
            chr = consoleReader.Read();
            if (chr < '0' || chr > '9')
                return ans;
            ans = ans * 10 + (uint)(chr - '0');
        }
    }

    private static long RL()
    {
        long ans = 0;
        int mul = 1;
        do
        {
            ans = consoleReader.Read();
            if (ans == -1)
                return 0;
            if (ans == '-') mul = -1;
        } while (ans < '0' || ans > '9');

        ans -= '0';
        while (true)
        {
            int chr = consoleReader.Read();
            if (chr < '0' || chr > '9')
                return ans * mul;
            ans = ans * 10 + chr - '0';
        }
    }

    private static int[] RIA(int n)
    {
        int[] ans = new int[n];
        for (int i = 0; i < n; i++)
            ans[i] = RI();
        return ans;
    }

    private static long[] RLA(int n)
    {
        long[] ans = new long[n];
        for (int i = 0; i < n; i++)
            ans[i] = RL();
        return ans;
    }

    private static char[] ReadWord()
    {
        int ans;

        do
        {
            ans = consoleReader.Read();
        } while (!((ans >= 'a' && ans <= 'z') || (ans >= 'A' && ans <= 'Z')));

        List<char> s = new List<char>();
        do
        {
            s.Add((char)ans);
            ans = consoleReader.Read();
        } while ((ans >= 'a' && ans <= 'z') || (ans >= 'A' && ans <= 'Z'));

        return s.ToArray();
    }

    private static char[] ReadString(int n)
    {
        int ans;

        do
        {
            ans = consoleReader.Read();
        } while (!((ans >= 'a' && ans <= 'z') || (ans >= 'A' && ans <= 'Z')));

        char[] s = new char[n];
        int pos = 0;
        do
        {
            s[pos++] = (char)ans;
            if (pos == n) break;
            ans = consoleReader.Read();
        } while ((ans >= 'a' && ans <= 'z') || (ans >= 'A' && ans <= 'Z'));

        return s;
    }

    private static char[] ReadStringLine()
    {
        int ans;

        do
        {
            ans = consoleReader.Read();
        } while (ans == 10 || ans == 13);

        List<char> s = new List<char>();

        do
        {
            s.Add((char)ans);
            ans = consoleReader.Read();
        } while (ans != 10 && ans != 13);

        return s.ToArray();
    }

    private static char ReadLetter()
    {
        while (true)
        {
            int ans = consoleReader.Read();
            if ((ans >= 'a' && ans <= 'z') || (ans >= 'A' && ans <= 'Z'))
                return (char)ans;
        }
    }
    private static char ReadNonLetter()
    {
        while (true)
        {
            int ans = consoleReader.Read();
            if (!((ans >= 'a' && ans <= 'z') || (ans >= 'A' && ans <= 'Z')))
                return (char)ans;
        }
    }

    private static char ReadAnyOf(IEnumerable<char> allowed)
    {
        while (true)
        {
            char ans = (char)consoleReader.Read();
            if (allowed.Contains(ans))
                return ans;
        }
    }

    private static char ReadDigit()
    {
        while (true)
        {
            int ans = consoleReader.Read();
            if (ans >= '0' && ans <= '9')
                return (char)ans;
        }
    }

    private static int ReadDigitInt()
    {
        return ReadDigit() - (int)'0';
    }

    private static char ReadAnyChar()
    {
        return (char)consoleReader.Read();
    }

    private static string DoubleToString(double x)
    {
        return x.ToString(CultureInfo.InvariantCulture);
    }

    private static double DoubleFromString(string x)
    {
        return double.Parse(x, CultureInfo.InvariantCulture);
    }

    static Program()
    {
        //Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;
        consoleReader = new StreamReader(Console.OpenStandardInput(BufferSize), Encoding.ASCII, false, BufferSize);
    }

    private static void PushTestData(StringBuilder sb)
    {
        PushTestData(sb.ToString());
    }
    private static void PushTestData(string data)
    {
#if TOLYAN_TEST
        if (testData == null)
        {
            testData = new MemoryStream();
            consoleReader = new StreamReader(testData);
        }

        var pos = testData.Position;
        var bytes = Encoding.UTF8.GetBytes(data);
        testData.Write(bytes, 0, bytes.Length);
        testData.Flush();
        testData.Position = pos;
#endif
    }
    #endregion
}


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

namespace _735D
{
    class Program
    {
        static bool IsPrime(long x)
        {
            if (x == 2)
            {
                return true;
            }
            else
            {
                var boundary = (int)Math.Floor(Math.Sqrt(x));
                for (int i = 2; i <= boundary; ++i)
                {
                    if (x % i == 0) return false;
                }
                return true;
            }
        }

        static void Main(string[] args)
        {
            long n = long.Parse(Console.ReadLine());
            if (IsPrime(n))
            {
                Console.WriteLine("1");
            }
            else if (n % 2 == 0 || IsPrime(n - 2))
            {
                Console.WriteLine("2");
            }
            else
            {
                Console.WriteLine("3");
            }
            //Console.ReadLine();
        }
    }
}


/*
csc -debug C.cs && mono --debug C.exe <<< "3 3 0"
*/

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

public class HelloWorld {
    static public void Main () {
        SolveCodeForces();
    }

    public static void SolveCodeForces() {
        var sc = new Scanner();
        var n = sc.NextInt();
        var m = sc.NextUlong();
        var k = sc.NextInt();

        const ulong MOD = 998244353ul;

        var S = new ulong[n, k+1];
        S[0, 0] = m;

        for (var i = 1; i < n; i++) {

            S[i, 0] = m;

            for (var j = 1; j <= k; j++) {
                S[i, j] = (  S[i-1, j-1] * (m-1) + S[i-1, j]  ) % MOD;
            }

        }

        System.Console.WriteLine(S[n-1, k]);
    }
}

public static class Helpers {
    public static T[] CreateArray<T>(int length, Func<int, T> itemCreate) {
        var result = new T[length];
        for (var i = 0; i < result.Length; i++)
            result[i] = itemCreate(i);
        return result;
    }

    public static T ElementWithMax<T>(this IEnumerable<T> seq, Func<T, long> func) {
        var bi = default(T);
        var bv = long.MinValue;
        foreach (var item in seq) {
            var v = func(item);
            if (v > bv) {
                bi = item;
                bv = v;
            }
        }
        return bi;
    }

    public static IEnumerable<int> IndicesWhere<T>(this IEnumerable<T> seq, Func<T, bool> cond) {
        var i = 0;
        foreach (var item in seq) {
            if (cond(item)) yield return i;
            i++;
        }
    }
}

public class Scanner
{
    private string[] line = new string[0];
    private int index = 0;

    public string Next() {
        if (line.Length <= index) {
            line = Console.ReadLine().Split(' ');
            index = 0;
        }
        var res = line[index];
        index++;
        return res;
    }

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

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

    public ulong NextUlong() {
        return ulong.Parse(Next());
    }

    public string[] Array() {
        line = Console.ReadLine().Split(' ');
        index = line.Length;
        return line;
    }

    public int[] IntArray() {
        var array = Array();
        var result = new int[array.Length];
        for (int i = 0; i < array.Length; i++)
            result[i] = int.Parse(array[i]);
        return result;
    }

    public long[] LongArray() {
        var array = Array();
        var result = new long[array.Length];
        for (int i = 0; i < array.Length; i++)
            result[i] = long.Parse(array[i]);
        return result;
    }

    public ulong[] UlongArray() {
        var array = Array();
        var result = new ulong[array.Length];
        for (int i = 0; i < array.Length; i++)
            result[i] = ulong.Parse(array[i]);
        return result;
    }
}


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

namespace codeforces
{

    class Program
    {
        const int N = 2000;
        const int MOD = 998244353;

        static int n, m, k;
        static int[,] dp = new int[N, N];

        static int mul(int a, int b)
        {
            return (int) ((1L * a * b) % MOD);
        }

        static int add(int a, int b)
        {
            int result = a + b;
            if (result >= MOD)
            {
                result -= MOD;
            }
            return result;
        }

        static void Main(string[] args)
        {
            var s = Console.ReadLine().Split(' ');
            n = int.Parse(s[0]);
            m = int.Parse(s[1]);
            k = int.Parse(s[2]);
            for (int i = 0; i < n; ++i)
            {
                for (int j = 0; j < n; ++j)
                {
                    dp[i, j] = 0;
                }
            }
            dp[0, 0] = m;
            for (int i = 1; i < n; ++i)
            {
                for (int j = 0; j <= i; ++j)
                {
                    dp[i, j] = j == 0
                        ? dp[i - 1, j]
                        : add(dp[i - 1, j], mul(m - 1, dp[i - 1, j - 1]));
                }
            }
            Console.WriteLine(dp[n - 1, k]);
        }
    }
}


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

namespace HayCragrer
{
    class Problem4
    {
        static void Main(string[] args)
        {
            int[] coords = new int[4];
            string[] text = Console.ReadLine().Split();
            string[] text1 = Console.ReadLine().Split();
            int[] steps = new int[2];
            for (int i = 0; i < 4; i++)
            {
                coords[i] = int.Parse(text[i]);
            }
            for (int i = 0; i < 2; i++)
            {
                steps[i] = int.Parse(text1[i]);
            }
            int x = coords[2] - coords[0];
            int y = coords[3] - coords[1];
            if ((x % steps[0] == 0) && (y % steps[1] == 0))
            {
                if ((x / steps[0] -y / steps[1]) % 2==0)
                {
                    Console.WriteLine("YES");
                }
                else
                {
                    Console.WriteLine("NO");
                }

            }
            else
            {
                Console.WriteLine("NO");
            }
        }
    }
}


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

namespace Codeforces
{
    class P817A
    {
        static void Main(string[] args)
        {
            string[] input1 = Console.ReadLine().Split();
            int x1 = int.Parse(input1[0]);
            int y1 = int.Parse(input1[1]);
            int x2 = int.Parse(input1[2]);
            int y2 = int.Parse(input1[3]);
            string[] input2 = Console.ReadLine().Split();
            int x = int.Parse(input2[0]);
            int y = int.Parse(input2[1]);
            Console.WriteLine((Math.Abs(x1 - x2) % x == 0 && Math.Abs(y1 - y2) % y == 0 && (Math.Abs(x1 - x2) / x) % 2 == (Math.Abs(y1 - y2) / y) % 2) ? "YES" : "NO");
        }
    }
}


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

namespace CodeForces.C664
{
    class Pa
    {
        static void Main(string[] args)
        {
            string[] numbers = Console.ReadLine().Split(' ').ToArray();
            if (numbers[0] == numbers[1]) Console.WriteLine(numbers[0]);
            else Console.WriteLine(1);
        }
    }
}


using System;

namespace CSharp
{
    public class _664A
    {
        public static void Main()
        {
            string[] tokens = Console.ReadLine().Split();
            Console.WriteLine(tokens[0] == tokens[1] ? tokens[0] : "1");
        }
    }
}


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

public class C1
{
  public static void Main ( )
  {
#if MYTRIAL
    Console.SetIn ( new StreamReader ( @"e:\zin.txt" ) );
#endif
    //solve ( );
    Console.WriteLine ( solve ( ) );
  }

  private static int solve ( )
  {
    long N = long.Parse ( Console.ReadLine ( ) );
    for ( int b = 0; b <= 90; b++ )
    {
      long D = GetDisc ( 1, b, -N );
      if ( D < 0 )
        continue;
      long sqrtd = ( long ) Math.Sqrt ( D );
      if ( sqrtd * sqrtd != D )
        continue;
      double x1 = ( -b + sqrtd ) / 2.0;
      if ( x1 == Math.Floor ( x1 ) && x1 >= 0 )
      {
        if ( b == sumd ( ( int ) x1 ) )
          return ( int ) x1;
      }

      double x2 = ( -b - sqrtd ) / 2.0;
      if ( x2 == Math.Floor ( x2 ) && x2 >= 0 )
      {
        if ( b == sumd ( ( int ) x2 ) )
          return ( int ) x2;
      }
    }

    return -1;
  }

  static int sumd ( int x )
  {
    int sum=0;
    while ( x > 0 )
    {
      sum += x % 10;
      x = x / 10;
    }
    return sum;
  }

  static long GetDisc ( long a, long b, long c )
  {
    return b * b - 4 * a * c;
  }

  public static int[] ReadLineToInts ( int length )
  {
    string line = Console.ReadLine ( ).Trim ( );
    string[] arStrings = line.Split ( ' ' );

    int[] ints = new int[length];
    for ( int i=0; i < length; i++ )
      ints[i] = int.Parse ( arStrings[i] );
    return ints;
  }

}


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

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            Int64 n = Convert.ToInt64(Console.ReadLine());

            int i, f = 0;
            Int64 s, d, x = -1;

            for (i = 1; i <= 90; i++)
            {
                d = i * i + 4 * n;
                s = (Int64)Math.Sqrt(d);
                if(s*s==d)
                {
                    x = (Int64)s - i;

                    if (x % 2 == 0)
                    {
                        x = (int)(s - i) / 2;
                        if (i == DigitSum(x))
                        {
                            f = 1;
                            break;
                        }
                    }
                }
            }

            if (f == 0)
                Console.WriteLine("-1");
            else
                Console.WriteLine(x);

        }

        private static int DigitSum(Int64 x)
        {
            int sum = 0;
            while (x != 0)
            {
                sum += (int)(x % 10);
                x /= 10;
            }
            return sum;
        }
    }
}


using System;
using System.Linq;
using System.Diagnostics;
using System.Collections.Generic;
using Debug = System.Diagnostics.Debug;
using StringBuilder = System.Text.StringBuilder;
using System.Numerics;
namespace Program
{

    public class Solver
    {
        public void Solve()
        {
            var n = sc.Integer();
            var T = sc.Integer();
            var a = sc.Integer(n);
            var v = a.Distinct().ToList();
            v.Sort();
            for (int i = 0; i < n; i++)
                a[i] = v.BinarySearch(a[i]);
            var m = v.Count;
            var mat = new TropicalMatrix(m, m);
            for (int i = 0; i < m; i++)
                for (int j = i; j < m; j++)
                {
                    var dp = Enumerate(n + 1, x => 1L << 60);
                    foreach (var x in a)
                    {
                        if (x < i || x > j) continue;
                        dp[dp.UpperBound(x)] = x;
                    }
                    mat[i, j] = dp.LowerBound(1L << 60);
                    Debug.WriteLine("{0} {1} {2}", i, j, mat[i, j]);
                }
            var ret = TropicalMatrix.Pow(mat, T);
            IO.Printer.Out.WriteLine(ret[0, m - 1]);
        }
        public IO.StreamScanner sc = new IO.StreamScanner(Console.OpenStandardInput());
        static T[] Enumerate<T>(int n, Func<int, T> f) { var a = new T[n]; for (int i = 0; i < n; ++i) a[i] = f(i); return a; }
        static public void Swap<T>(ref T a, ref T b) { var tmp = a; a = b; b = tmp; }
    }

}

#region main
static class Ex
{
    static public string AsString(this IEnumerable<char> ie) { return new string(System.Linq.Enumerable.ToArray(ie)); }
    static public string AsJoinedString<T>(this IEnumerable<T> ie, string st = " ") { return string.Join(st, ie); }
    static public void Main()
    {
        var solver = new Program.Solver();
        solver.Solve();
        Program.IO.Printer.Out.Flush();
    }
}
#endregion
#region Ex
namespace Program.IO
{
    using System.IO;
    using System.Text;
    using System.Globalization;
    public class Printer : StreamWriter
    {
        static Printer() { Out = new Printer(Console.OpenStandardOutput()) { AutoFlush = false }; }
        public static Printer Out { get; set; }
        public override IFormatProvider FormatProvider { get { return CultureInfo.InvariantCulture; } }
        public Printer(System.IO.Stream stream) : base(stream, new UTF8Encoding(false, true)) { }
        public Printer(System.IO.Stream stream, Encoding encoding) : base(stream, encoding) { }
        public void Write<T>(string format, T[] source) { base.Write(format, source.OfType<object>().ToArray()); }
        public void WriteLine<T>(string format, T[] source) { base.WriteLine(format, source.OfType<object>().ToArray()); }
    }
    public class StreamScanner
    {
        public StreamScanner(Stream stream) { str = stream; }
        public readonly Stream str;
        private readonly byte[] buf = new byte[1024];
        private int len, ptr;
        public bool isEof = false;
        public bool IsEndOfStream { get { return isEof; } }
        private byte read()
        {
            if (isEof) return 0;
            if (ptr >= len) { ptr = 0; if ((len = str.Read(buf, 0, 1024)) <= 0) { isEof = true; return 0; } }
            return buf[ptr++];
        }
        public char Char() { byte b = 0; do b = read(); while ((b < 33 || 126 < b) && !isEof); return (char)b; }

        public string Scan()
        {
            var sb = new StringBuilder();
            for (var b = Char(); b >= 33 && b <= 126; b = (char)read())
                sb.Append(b);
            return sb.ToString();
        }
        public string ScanLine()
        {
            var sb = new StringBuilder();
            for (var b = Char(); b != '\n'; b = (char)read())
                if (b == 0) break;
                else if (b != '\r') sb.Append(b);
            return sb.ToString();
        }
        public long Long()
        {
            if (isEof) return long.MinValue;
            long ret = 0; byte b = 0; var ng = false;
            do b = read();
            while (b != 0 && b != '-' && (b < '0' || '9' < b));
            if (b == 0) return long.MinValue;
            if (b == '-') { ng = true; b = read(); }
            for (; true; b = read())
            {
                if (b < '0' || '9' < b)
                    return ng ? -ret : ret;
                else ret = ret * 10 + b - '0';
            }
        }
        public int Integer() { return (isEof) ? int.MinValue : (int)Long(); }
        public double Double() { var s = Scan(); return s != "" ? double.Parse(Scan(), CultureInfo.InvariantCulture) : double.NaN; }
        private T[] enumerate<T>(int n, Func<T> f)
        {
            var a = new T[n];
            for (int i = 0; i < n; ++i) a[i] = f();
            return a;
        }

        public char[] Char(int n) { return enumerate(n, Char); }
        public string[] Scan(int n) { return enumerate(n, Scan); }
        public double[] Double(int n) { return enumerate(n, Double); }
        public int[] Integer(int n) { return enumerate(n, Integer); }
        public long[] Long(int n) { return enumerate(n, Long); }
    }
}
#endregion
#region Tropical Matrix
public class TropicalMatrix
{
    int row, col;
    public long[] mat;
    const long min = -1L << 60;
    public long this[int r, int c]
    {
        get { return mat[r * col + c]; }
        set { mat[r * col + c] = value; }
    }
    public TropicalMatrix(int r, int c)
    {
        row = r; col = c;
        mat = new long[row * col];
        for (int i = 0; i < row * col; i++)
            mat[i] = min;
    }
    public static TropicalMatrix operator +(TropicalMatrix l, TropicalMatrix r)
    {
        check(l, r);
        var ret = new TropicalMatrix(l.row, l.col);
        for (int i = 0; i < l.row; i++)
            for (int j = 0; j < l.col; j++)
                ret.mat[i * ret.col + j] = Math.Max(l.mat[i * l.col + j], r.mat[i * r.col + j]);
        return ret;

    }
    public static TropicalMatrix operator *(TropicalMatrix l, TropicalMatrix r)
    {
        checkMul(l, r);
        var ret = new TropicalMatrix(l.row, l.col);

        for (int i = 0; i < l.row; i++)
            for (int k = 0; k < l.row; k++)
                for (int j = 0; j < l.col; j++)
                    ret.mat[i * l.col + j] = Math.Max(ret.mat[i * l.col + j],
                        l.mat[i * l.col + k] + r.mat[k * l.col + j]);
        return ret;
    }
    public static TropicalMatrix Pow(TropicalMatrix m, long n)
    {
        var ret = new TropicalMatrix(m.row, m.col);
        for (int i = 0; i < m.row; i++)
            ret.mat[i * m.col + i] = 0;
        for (; n > 0; m *= m, n >>= 1)
            if ((n & 1) == 1)
                ret = ret * m;
        return ret;

    }
    public static TropicalMatrix Trans(TropicalMatrix m)
    {
        var ret = new TropicalMatrix(m.col, m.row);
        for (int i = 0; i < m.row; i++)
            for (int j = 0; j < m.col; j++)
                ret.mat[j * m.col + i] = m.mat[i * m.col + j];
        return ret;
    }
    [System.Diagnostics.Conditional("DEBUG")]
    static private void check(TropicalMatrix a, TropicalMatrix b)
    {
        if (a.row != b.row || a.col != b.col)
            throw new Exception("row and col have to be same.");

    }
    [System.Diagnostics.Conditional("DEBUG")]
    static private void checkMul(TropicalMatrix a, TropicalMatrix b)
    {
        if (a.col != b.row)
            throw new Exception("row and col have to be same.");

    }
}
#endregion

#region BinarySearch for long[]
static public partial class Algorithm
{

    static public int LowerBound(this long[] arr, long v)
    {
        int l = 0, h = arr.Length - 1;
        while (l <= h)
        {
            int m = ((h + l) >> 1);
            if (arr[m] < v) l = m + 1;
            else h = m - 1;
        }
        return l;
    }
    static public int UpperBound(this long[] a, long v)
    {
        int l = 0, h = a.Length - 1;
        while (l <= h)
        {
            int m = ((h + l) >> 1);
            if (a[m] <= v) l = m + 1;
            else h = m - 1;
        }
        return l;
    }

}
#endregion


using System;
using System.IO;
using System.Linq;
using System.Text;

namespace Once_Again
{
    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 T = Next();

            var nn = new int[n];
            for (int i = 0; i < n; i++)
            {
                nn[i] = Next();
            }

            var maxK = new int[nn.Max() + 1];
            foreach (int i in nn)
            {
                maxK[i]++;
            }
            int maxx = maxK.Max();

            var max1 = new int[nn.Max() + 1];

            for (int t = 1; t <= 102; t++)
            {
                for (int i = 0; i < n; i++)
                {
                    int m = 0;
                    for (int j = 0; j <= nn[i]; j++)
                    {
                        if (m < max1[j])
                            m = max1[j];
                    }
                    max1[nn[i]] = m + 1;
                }
                if (T == t)
                {
                    writer.WriteLine(max1.Max());
                    writer.Flush();
                    return;
                }
            }

            writer.WriteLine(max1.Max() + maxx*(T - 102));
            writer.Flush();
        }

        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.Linq;
using System.Text;

namespace CodeForces
{
    class R172_Div2_B
    {
        static void Main(string[] args)
        {
            string[] s = Console.ReadLine().Split();
            int x = int.Parse(s[0]);
            int y = int.Parse(s[1]);
            int n = int.Parse(s[2]);
            double dx = (double) x;
            double dy = (double) y;

            long mina = 0, minb = 0;
            double min = long.MaxValue;
            for (long b = 1; b <= n; b++)
            {
                double db = (double)b;
                long aMin = b * x / y;
                long aMax = Convert.ToInt64(Math.Ceiling(db * dx / dy));

                for (long a = aMin; a <= aMax; a++)
                {
                    double da = (double)a;
                    double d = Math.Abs(dx / dy - da / db);
                    d = Math.Floor(d * 1e15) / 1e15;
                    if (d < min)
                    {
                        min = d;
                        mina = a;
                        minb = b;
                    }
                }
            }

            Console.WriteLine(mina + "/" + minb);

        }
    }
}


using System;
using System.IO;
using System.Linq;

namespace Codeforces.R281.B
{
    public static class Solver
    {
        public static void Main()
        {
            using (var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false })
            {
                Solve(Console.In, sw);
            }
        }

        public static void Solve(TextReader tr, TextWriter tw)
        {
            var w = tr.ReadLine().Split().Select(x => int.Parse(x)).ToArray();
            tw.WriteLine(Calc(w[0], w[1], w[2]));
        }

        private static string Calc(int x, int y, int n)
        {
            var e = long.MaxValue;
            var eDenominator = 1L;

            var resA = 0L;
            var resB = 0L;

            for (var b = 1L; b <= n; ++b)
            {
                var l = 0L;
                var h = (x / y + 1) * b + 3;

                for (; l + 2 < h; )
                {
                    var m1 = (l * 2 + h) / 3;
                    var m2 = (l + h * 2) / 3;
                    var err1 = Math.Abs(x * b - y * m1);
                    var err2 = Math.Abs(x * b - y * m2);

                    if (err1 <= err2)
                    {
                        h = m2;
                    }
                    else
                    {
                        l = m1;
                    }
                }

                for (var a = l; a <= h; ++a)
                {
                    var currentError = Math.Abs(x * b - y * a);
                    if (currentError * eDenominator < e * b)
                    {
                        e = currentError;
                        eDenominator = b;
                        resA = a;
                        resB = b;
                    }
                }
            }

            return resA + "/" + resB;
        }
    }
}