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

namespace Codeforces
{
    internal class Program
    {
        private static void Main()
        {
            if (Debugger.IsAttached)
            {
                Console.SetIn(new StreamReader(@"..\..\..\..\Tests\D7.in"));
            }

            Solve();

            if (Debugger.IsAttached)
            {
                Console.In.Close();
                Console.SetIn(new StreamReader(Console.OpenStandardInput()));
                Console.ReadLine();
            }
        }

        private static void Solve()
        {
            var s = Read();
            var intF = new int[10];
            var intS = new int[10];
            foreach (var n in s)
            {
                intF[n - '0']++;
                intS[n - '0']++;
            }

            var max = 0;
            var maxIndex = -1;
            for (int i = 1; i < 10; i++)
            {
                var res = 0;
                var j = 10 - i;
                if(intF[i] > 0 && intS[j] > 0)
                {
                    intF[i]--;
                    intS[j]--;
                    res++;
                    for (int k = 0; k < 10; k++)
                    {
                        res += Math.Min(intF[k], intS[9 - k]);
                    }
                    intF[i]++;
                    intS[j]++;
                }
                if(max < res)
                {
                    max = res;
                    maxIndex = i;
                }
            }
            var resF = new StringBuilder();
            var resS = new StringBuilder();
            if (maxIndex != -1)
            {
                intF[maxIndex]--;
                intS[(10 - maxIndex)%10]--;
                resF.Append(maxIndex);
                resS.Append((10 - maxIndex)%10);
            }
            for (int i = 0; i < 10; i++)
            {
                var count = Math.Min(intF[i], intS[9 - i]);
                resF.Append(i.ToString()[0], count);
                resS.Append((9-i).ToString()[0], count);
                intF[i] -= count;
                intS[9 - i] -= count;
            }
            var countZero = Math.Min(intF[0], intS[0]);
            resF.Insert(0, "0", countZero);
            resS.Insert(0, "0", countZero);
            intF[0] -= countZero;
            intS[0] -= countZero;
            for (int i = 0; i < 10; i++)
            {
                resF.Append(i.ToString()[0], intF[i]);
                resS.Append(i.ToString()[0], intS[i]);
            }

            Console.WriteLine(new string(resF.ToString().Reverse().ToArray()));
            Console.WriteLine(new string(resS.ToString().Reverse().ToArray()));
        }

        #region Reader

        private static string Read()
        {
            return Console.ReadLine();
        }

        private static string[] ReadArray()
        {
            return Console.ReadLine().Split(' ');
        }

        private static int[] ReadIntArray()
        {
            var input = Console.ReadLine().Split(' ').Select(Int32.Parse).ToArray();
            return input;
        }

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

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

        private static int ReadNextInt(string[] input, int index)
        {
            return Int32.Parse(input[index]);
        }

        #endregion
    }
}


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

namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
int[] inputData = Console.ReadLine().Split(' ').Select(x => Int32.Parse(x)).ToArray();
if (2 * inputData[2] > inputData[0] || 2 * inputData[2] > inputData[1])
{
Console.WriteLine("Second");
}
else
{
Console.WriteLine("First");
}

}
}
}


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

namespace test
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] s = Console.ReadLine().Split();
            int[] m = new int[s.Length];
            int k = 0;
            for (int i = 0; i < s.Length; i++)
                m[i] = int.Parse(s[i]);
            Array.Sort(m);
            for (int i = 0; i < m.Length - 1; i++)
                if (m[i] == m[i + 1])
                    k++;
            Console.WriteLine(k);
        }
    }
}


using System;
using System.Collections.Generic;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            var words = Console.ReadLine().Split(' ');
            long n, m;
            n = Convert.ToInt64(words[0]);
            m = Convert.ToInt64(words[1]);
            words = Console.ReadLine().Split(' ');
            long[] numbers = new long[n+1];
            long[] steps = new long[m + 1];
            bool[] usernumbers = new bool[n + 1];
            for (int i = 1; i <= m; ++i)
            {
                steps[i] = Convert.ToInt64(words[i - 1]);
            }
            for (int i = 1; i < m; ++i)
            {
                long diff = 0;
                if (steps[i + 1] <= steps[i])
                {
                    diff += n - steps[i] + steps[i + 1];
                } else
                {
                    diff = steps[i + 1] - steps[i];
                }
                if (numbers[steps[i]] != 0 && numbers[steps[i]] != diff)
                {
                    Console.WriteLine(-1);
                    return;
                } else if (numbers[steps[i]] != 0 && numbers[steps[i]] == diff)
                {
                    continue;
                }
                if (usernumbers[diff] == true)
                {
                    Console.WriteLine(-1);
                    return;
                }
                numbers[steps[i]] = diff;
                usernumbers[diff] = true;
            }
            for (int i = 1, j = 1; i <= n && j <=n;)
            {
                if (usernumbers[j] == true)
                {
                    ++j;
                    continue;
                }
                if (numbers[i] == 0)
                {
                    numbers[i] = j;
                    ++j;++i;
                } else
                {
                    ++i;
                }
            }
            for (int i = 1; i<n+1; ++i)
            {
                Console.Write(numbers[i] + " ");
            }

        }
    }
}


using System;
using System.Text;

class Program
{
    static void Main(string[] args)
    {
        string line = Console.ReadLine();

        int nb4 = 0, nb7 = 0;
        for (int i = 0; i < line.Length; i++)
        {
            if (line[i] == '4') nb4++;
            else if (line[i] == '7') nb7++;
        }

        if (nb4 + nb7 == 0)
            Console.WriteLine("-1");
        else
        {
            if (nb4 >= nb7)
                Console.WriteLine("4");
            else
                Console.WriteLine("7");
        }
    }

}


using System;
using System.Linq;

namespace CSharp
{
    class _808A
    {
        public static void Main()
        {
            string n = Console.ReadLine();
            Console.WriteLine(int.Parse(string.Concat(Enumerable.Range(0, n.Length).Select(i => i == 0 ? n[0] - '0' + 1 : 0))) - int.Parse(n));
        }
    }
}


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

class TEST{
	static void Main(){
		Sol mySol =new Sol();
		mySol.Solve();
	}
}

class Sol{
	public void Solve(){

		long N2 = (N + 1) / 2;
		long l = 0;
		long r = N;
		while(r - l > 1){

			long c = (l + r) / 2;
			long g = 0;
			long tot = N;
			while(tot > 0){
				g += Math.Min(c, tot);
				tot -= Math.Min(c, tot);
				tot -= tot / 10;
			}

			if(g < N2){
				l = c;
			} else {
				r = c;
			}
		}
		Console.WriteLine(r);
	}
	long N;
	public Sol(){
		N = rl();
	}

	static String rs(){return Console.ReadLine();}
	static int ri(){return int.Parse(Console.ReadLine());}
	static long rl(){return long.Parse(Console.ReadLine());}
	static double rd(){return double.Parse(Console.ReadLine());}
	static String[] rsa(char sep=' '){return Console.ReadLine().Split(sep);}
	static int[] ria(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>int.Parse(e));}
	static long[] rla(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>long.Parse(e));}
	static double[] rda(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>double.Parse(e));}
}


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

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            string s;
            byte b;
            s = Console.ReadLine();
            if (byte.TryParse(s, out b) && b < 100)
            {
                string result = string.Empty;
                if (0 <= b && b <= 20 || b % 10 == 0)
                {
                    result = NumberToString(b);
                }
                else
                {
                    byte first = Convert.ToByte(b % 10);
                    byte second = Convert.ToByte(Convert.ToByte(b / 10) * 10);
                    result = NumberToString(second);
                    result = string.Format("{0}-{1}", result, NumberToString(first));
                }
                Console.WriteLine(result);
            }
            Console.ReadLine();
        }

        static string NumberToString(byte N)
        {
            switch (N)
            {
                case 0:
                    return "zero";
                case 1:
                    return "one";
                case 2:
                    return "two";
                case 3:
                    return "three";
                case 4:
                    return "four";
                case 5:
                    return "five";
                case 6:
                    return "six";
                case 7:
                    return "seven";
                case 8:
                    return "eight";
                case 9:
                    return "nine";
                case 10:
                    return "ten";
                case 11:
                    return "eleven";
                case 12:
                    return "twelve";
                case 13:
                    return "thirteen";
                case 14:
                    return "fourteen";
                case 15:
                    return "fifteen";
                case 16:
                    return "sixteen";
                case 17:
                    return "seventeen";
                case 18:
                    return "eighteen";
                case 19:
                    return "nineteen";
                case 20:
                    return "twenty";
                case 30:
                    return "thirty";
                case 40:
                    return "forty";
                case 50:
                    return "fifty";
                case 60:
                    return "sixty";
                case 70:
                    return "seventy";
                case 80:
                    return "eighty";
                case 90:
                    return "ninety";
            }
            return string.Empty;
        }
    }
}


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

namespace Task
{
  class Program
  {
    #region Read / Write
    protected static TextReader reader;
    protected static TextWriter writer;
    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=

    public static bool NextPermutation(List<int> perm)
    {
      for (int i = perm.Count - 2; i >= 0; i--)
      {
        if (perm[i] < perm[i + 1])
        {
          int min = i + 1;
          for (int j = min; j < perm.Count; j++)
            if (perm[j] > perm[i] && perm[j] < perm[min])
              min = j;

          int tmp = perm[i];
          perm[i] = perm[min];
          perm[min] = tmp;
          perm.Reverse(i + 1, perm.Count - i - 1);
          return true;
        }
      }

      return false;
    }

    public static int[] Perm(int[] mas1, int[] mas2, int numb1 = 0)
    {
      if (mas1 == null)
        return mas2;
      if (mas2 == null)
        return mas1;

      var ans = new int[mas1.Length];
      for (int i = 0; i < mas1.Length; i++)
      {
        ans[i] = mas2[mas1[i] - 1];
      }

      return ans;
    }

    public static void Build(int[][] a, int v, int tl, int tr)
    {
      hash = new Dictionary<long, int[]>();

      if (tl == tr)
        t[v] = a[tl];
      else
      {
        int tm = (tl + tr) / 2;
        Build(a, v * 2, tl, tm);
        Build(a, v * 2 + 1, tm + 1, tr);
        t[v] = Perm(t[v * 2], t[v * 2 + 1]);
      }
    }

    public static Dictionary<long, int[]> hash;

    public static int[] Query(int v, int tl, int tr, int l, int r)
    {
      if (l > r)
        return null;
      if (l == tl && r == tr)
        return t[v];

      var key = ((long)l << 17) + r;
      if (hash.ContainsKey(key))
        return hash[key];

      int tm = (tl + tr) / 2;
      var res = Perm(Query(v * 2, tl, tm, l, Math.Min(r, tm)), Query(v * 2 + 1, tm + 1, tr, Math.Max(l, tm + 1), r));
      hash[key] = res;
      return res;
    }

    public static int[][] t;

    static void Main(string[] args)
    {
      //long i = 0;
      long ans = 0;
      reader = new StreamReader(Console.OpenStandardInput());
      writer = new StreamWriter(Console.OpenStandardOutput());

      var n = ReadInt();
      var B = ReadInt();
      var mas = ReadIntArray();
      //var mas = ReadIntArray().Select((item, index) => new Tuple<int, int>(index, item)).ToArray();

      var lst = new List<int>();
      int evenNumb = 0, oddNumb = 0;
      for (int i = 0; i < n - 1; i++)
      {
        if ((mas[i] & 1) == 0)
        {
          evenNumb++;
        }
        else
        {
          oddNumb++;
        }

        if (evenNumb == oddNumb)
          lst.Add(Math.Abs(mas[i] - mas[i + 1]));
      }

      lst.Sort();
      for (int i = 0; i < lst.Count; i++)
      {
        if (lst[i] <= B)
        {
          ans++;
          B -= lst[i];
        }
        else
        {
          break;
        }
      }

      Write(ans);

      reader.Close();
      writer.Close();
    }
  }
}


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

namespace Exams
{
    class Program
    {
        private static int n;

        private static int k;

        static void Main(string[] args)
        {
            int[] values = Console.ReadLine().Split(' ').Select(s => Convert.ToInt32(s)).ToArray();
            n = values[0];
            k = values[1];

            int result = Solve();
            Console.Out.WriteLine(result);
        }

        private static int Solve()
        {
            for(int i2 = 0; i2 <= n; i2++)
            {
                for(int i3 = 0; i3 <= n - i2; i3++)
                {
                    for(int i4 = 0; i4 <= n - i3 - i2;i4++)
                    {
                        int i5 = n - i4 - i3 - i2;
                        int sum = 2 * i2 + 3 * i3 + 4 * i4 + 5 * i5;

                        if (sum == k)
                        {
//                            Console.Out.WriteLine("{4} = 2 * {0} + 3 * {1} + 4 * {2} + 5 * {3}", i2, i3, i4, i5, sum);

                            return i2;
                        }
                    }
                }
            }

            throw new ArgumentException("no possibility to pass exam");
        }
    }
}


using System;
using System.IO;
using System.Net;
using System.Net.Sockets;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Numerics;
using System.Threading.Tasks;
using System.Text.RegularExpressions;
using static System.Math;
using MethodImplOptions = System.Runtime.CompilerServices.MethodImplOptions;
using MethodImplAttribute = System.Runtime.CompilerServices.MethodImplAttribute;

public static class P
{
    public static void Main()
    {
        int b = int.Parse(Console.ReadLine());
        var g = int.Parse(Console.ReadLine());
        var n = int.Parse(Console.ReadLine());
        var gMin = Max(n - b, 0);
        var gMax = Min(n, g);
        Console.WriteLine(gMax - gMin + 1);
    }

    static readonly TextReader In = Console.In;
    static int NextInt
    {
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        get
        {
            int res = 0;
            int next = In.Read();
            int rev = 1;
            while (45 > next || next > 57) next = In.Read();
            if (next == 45) { next = In.Read(); rev = -1; }
            while (48 <= next && next <= 57)
            {
                res = res * 10 + next - 48;
                next = In.Read();
            }
            return res * rev;
        }
    }
}


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

namespace CodeForces
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.ReadLine();
            string[] input = Console.ReadLine().Split(' ');
            int temp = -1;
            int temp2 = 0;
            for (int i = 0; i < input.Count(); i++)
            {
                temp2 = input[i].Count(c => char.IsUpper(c));
                temp = (temp2 > temp) ? temp2 : temp;
            }
            Console.WriteLine(temp);
        }
    }
}


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

// (づ°ω°)づﾐe★゜・。。・゜゜・。。・゜☆゜・。。・゜゜・。。・゜
public class Solution
{
    const int MAXN = 50;
    const int MAX_INV = MAXN * MAXN;

    long Fun(int n, int mod)
    {
        var d = new long[MAX_INV];
        d[0] = 1;
        int max = 0;
        long ans = 0;
        for (int i = 1; i < n; i++)
        {
            var nd = new long[MAX_INV];
            int nmax = max;
            long sum = 0;
            for (int j = 0; j <= i; j++)
                for (int k = 0; k <= i; k++)
                {
                    for (int p = 0; p <= max; p++)
                    {
                        int o = p + j - k;
                        nmax = Math.Max(nmax, o);
                        if (o >= 0)
                        {
                            nd[o] = (nd[o] + d[p]) % mod;
                            if (j < k && o > 0)
                                sum = (sum + d[p]) % mod;
                        }
                        if (p == 0)
                            continue;
                        o = -p + j - k;
                        nmax = Math.Max(nmax, o);
                        if (o >= 0)
                        {
                            nd[o] = (nd[o] + d[p]) % mod;
                            if (j < k && o > 0)
                                sum = (sum + d[p]) % mod;
                        }
                    }
                }
            ans = ((i + 1) * ans + sum) % mod;
            max = nmax;
            d = nd;
        }

        return ans;
    }

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

        Write(Fun(n, mod));
    }

    #region Main

    protected static TextReader reader;
    protected static TextWriter writer;
    static void Main()
    {
#if DEBUGLOCAL
        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());
        //reader = new StreamReader("ysys.in");
        //writer = new StreamWriter("output.txt");
#endif
        try
        {
            new Solution().Solve();
            //var thread = new Thread(new Solution().Solve, 1024 * 1024 * 128);
            //thread.Start();
            //thread.Join();
        }
        catch (Exception ex)
        {
#if DEBUGLOCAL
            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;

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

            long n = long.Parse(tokens[0]);
            long a = long.Parse(tokens[1]);
            long b = long.Parse(tokens[2]);
            long p = long.Parse(tokens[3]);
            long q = long.Parse(tokens[4]);

            long s = n / a * p + n / b * q - n / LCM(a, b) * Math.Min(p, q);
            Console.WriteLine(s);
        }

        private static long LCM(long x, long y) => x / GCD(x, y) * y;

        private static long GCD(long x, long y) => x == 0 ? y : GCD(y % x, x);
    }
}


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

namespace CodeForces
{
    class Abracadabra
    {
        public static void Main()
        {
            string[] line = Console.ReadLine().Split(' ');
            int n1 = int.Parse(line[0]);
            int n2 = int.Parse(line[1]);
            int k1 = int.Parse(line[2]);
            int k2 = int.Parse(line[3]);

            var dp = new Dictionary<string, long>();
            var answer = recurse(n1, n2, k1, k2, 0, 0, dp, 0, 0, 0);
            Console.WriteLine(answer % 100000000);
        }

        public static long recurse(int s, int h, int k1, int k2, int sp, int hp, Dictionary<string, long> dp, int tsp, int thp, int total)
        {
            if (total == s + h)
            {
                return 1;
            }

            if (dp.ContainsKey(string.Format("{0},{1},{2},{3},{4}", sp, hp, tsp, thp, total)))
            {
                return dp[string.Format("{0},{1},{2},{3},{4}", sp, hp, tsp, thp, total)];
            }

            long a = 0;
            if (tsp < s && sp + 1 <= k1)
            {
                a = recurse(s, h, k1, k2, sp + 1, 0, dp, tsp + 1, thp, total + 1);
            }

            long b = 0;
            if (thp < h && hp + 1 <= k2)
            {
                b = recurse(s, h, k1, k2, 0, hp + 1, dp, tsp, thp + 1, total + 1);
            }

            long answer = a + b % 100000000;

            dp.Add(string.Format("{0},{1},{2},{3},{4}", sp, hp, tsp, thp, total), answer);

            return answer;
        }
    }
}


using System;
using System.Collections.Generic;
using System.Linq;
using CompLib.Util;

public class Program
{
    long A, B;
    public void Solve()
    {
        var sc = new Scanner();
        A = sc.NextLong();
        B = sc.NextLong();
        var div = Div(A + B);
        var divA = Div(A);
        var divB = Div(B);
        div.Sort();
        divA.Sort();
        divB.Sort();
        long ans = long.MaxValue;
        for (int i = 0; i <= div.Count / 2; i++)
        {

            long j = div[div.Count - 1 - i];

            // A,Bのどちらかが i以下、j以下の積で表せるか?
            {
                int ok = -1;
                int ng = divA.Count;
                while (ng - ok > 1)
                {
                    int mid = (ok + ng) / 2;
                    if (divA[mid] <= div[i]) ok = mid;
                    else ng = mid;
                }
                if(ok >= 0 && divA[divA.Count - ng] <= j)
                {
                    // Console.WriteLine($"A {div[i]} {j}");
                    ans = Math.Min(ans, (div[i] + j) * 2);
                    continue;
                }
            }

            {
                int ok = -1;
                int ng = divB.Count;
                while (ng - ok > 1)
                {
                    int mid = (ok + ng) / 2;
                    if (divB[mid] <= div[i]) ok = mid;
                    else ng = mid;
                }
                if (ok >= 0 && divB[divB.Count - ng] <= j)
                {
                    // Console.WriteLine($"B {div[i]} {j}");
                    ans = Math.Min(ans, (div[i] + j) * 2);
                    continue;
                }
            }
        }
        Console.WriteLine(ans);
    }

    public List<long> Div(long l)
    {
        var result = new List<long>();
        for (long i = 1; i * i <= l; i++)
        {
            if (l % i == 0)
            {
                result.Add(i);
                if (l / i != i) result.Add(l / i);
            }
        }
        return result;
    }
    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()
        {
            while (_index >= _line.Length)
            {
                _line = Console.ReadLine().Split(Separator);
                _index = 0;
            }

            return _line[_index++];
        }

        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()
        {
            _line = Console.ReadLine().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.IO;
using SB = System.Text.StringBuilder;
//using System.Threading.Tasks;
//using System.Text.RegularExpressions;
//using System.Globalization;
//using System.Diagnostics;
using static System.Console;
using System.Numerics;
using static System.Math;
using pair = Pair<int, int>;

class Program
{
    static void Main()
    {
        //SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
        new Program().solve();
        Out.Flush();
    }
    readonly Scanner cin = new Scanner();
    readonly int[] dd = { 0, 1, 0, -1, 0 }; //→↓←↑
    readonly int mod = 1000000007;
    readonly int dom = 998244353;
    bool chmax<T>(ref T a, T b) where T : IComparable<T> { if (a.CompareTo(b) < 0) { a = b; return true; } return false; }
    bool chmin<T>(ref T a, T b) where T : IComparable<T> { if (b.CompareTo(a) < 0) { a = b; return true; } return false; }

    void swap<T>(ref T a, ref T b)
    {
        var t = a;
        a = b;
        b = t;
    }
    void solve()
    {
        var A = cin.nextlong;
        var B = cin.nextlong;
        if (A == B)
        {
            WriteLine(0);
            return;
        }

        if (A > B)
        {
            swap(ref A, ref B);
        }

        var G = B - A; //G <= 10^9
        var L = new List<long>();
        for (long i = 1; i * i <= G; i++)
        {
            if (G % i == 0)
            {
                L.Add(i);
                var j = G / i;
                if (i != j) L.Add(j);
            }
        }

        long ans = long.MaxValue;
        long K = long.MaxValue;

        foreach (var v in L)
        {

            var key = A % v;
            if (key != 0) key = v - key;
            var ret = lcm(A + key, B + key);
            if (ret < ans)
            {
                ans = ret;
                K = key;
            }
            else if (ret == ans && key < K)
            {
                K = key;
            }

            //WriteLine(v + " " + ret + " " + ans);
        }

        WriteLine(K);
    }

    long gcd(long a, long b)
    {
        return (b != 0) ? gcd(b, a % b) : a;
    }
    long lcm(long a, long b)
    {
        return a / gcd(a, b) * b;
    }
    //ax + by = gcd(a, b)となるx, yを求める
    long extgcd(long a, long b, out long x, out long y)
    {
        long g = a;
        if (b != 0)
        {
            g = extgcd(b, a % b, out y, out x);
            y -= (a / b) * x;
        }
        else
        {
            x = 1;
            y = 0;
        }
        return g;
    }
}

static class Ex
{
    public static void join<T>(this IEnumerable<T> values, string sep = " ") => WriteLine(string.Join(sep, values));
    public static string concat<T>(this IEnumerable<T> values) => string.Concat(values);
    public static string reverse(this string s) { var t = s.ToCharArray(); Array.Reverse(t); return t.concat(); }

    public static int lower_bound<T>(this IList<T> arr, T val) where T : IComparable<T>
    {
        int low = 0, high = arr.Count;
        int mid;
        while (low < high)
        {
            mid = ((high - low) >> 1) + low;
            if (arr[mid].CompareTo(val) < 0) low = mid + 1;
            else high = mid;
        }
        return low;
    }
    public static int upper_bound<T>(this IList<T> arr, T val) where T : IComparable<T>
    {
        int low = 0, high = arr.Count;
        int mid;
        while (low < high)
        {
            mid = ((high - low) >> 1) + low;
            if (arr[mid].CompareTo(val) <= 0) low = mid + 1;
            else high = mid;
        }
        return low;
    }
}

class Pair<T, U> : IComparable<Pair<T, U>> where T : IComparable<T> where U : IComparable<U>
{
    public T f; public U s;
    public Pair(T f, U s) { this.f = f; this.s = s; }
    public int CompareTo(Pair<T, U> a) => f.CompareTo(a.f) != 0 ? f.CompareTo(a.f) : s.CompareTo(a.s);
    public override string ToString() => $"{f} {s}";
}

class Scanner
{
    string[] s; int i;
    readonly char[] cs = new char[] { ' ' };
    public Scanner() { s = new string[0]; i = 0; }
    public string[] scan => ReadLine().Split();
    public int[] scanint => Array.ConvertAll(scan, int.Parse);
    public long[] scanlong => Array.ConvertAll(scan, long.Parse);
    public double[] scandouble => Array.ConvertAll(scan, double.Parse);
    public string next
    {
        get
        {
            if (i < s.Length) return s[i++];
            string st = ReadLine();
            while (st == "") st = ReadLine();
            s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
            i = 0;
            return next;
        }
    }
    public int nextint => int.Parse(next);
    public long nextlong => long.Parse(next);
    public double nextdouble => double.Parse(next);
}


//

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

namespace sar_cs
{
    public class Program
    {
        public class Parser
        {
            const int BufSize = 25000;
            TextReader s;
            char[] buf = new char[BufSize];
            int bufPos;
            int bufDataSize;
            bool eos;   // eos read to buffer
            int lastChar = -2;
            int nextChar = -2;
            StringBuilder sb = new StringBuilder();

            void FillBuf()
            {
                if (eos) return;
                bufDataSize = s.Read(buf, 0, BufSize);
                if (bufDataSize == 0) eos = true;
                bufPos = 0;
            }

            int Read()
            {
                if (nextChar != -2)
                {
                    lastChar = nextChar;
                    nextChar = -2;
                }
                else
                {
                    if (bufPos == bufDataSize) FillBuf();
                    if (eos) lastChar = -1;
                    else lastChar = buf[bufPos++];
                }
                return lastChar;
            }

            void Back()
            {
                if (lastChar == -2) throw new Exception();  // no chars were ever read
                nextChar = lastChar;
            }

            public Parser()
            {
                s = Console.In;
            }

            public int ReadInt()
            {
                int res = 0;
                int sign = -1;
                int c;
                do { c = Read(); } while (c >= 0 && char.IsWhiteSpace((char)c));
                if (c == '-')
                {
                    sign = -sign;
                    c = Read();
                }
                int len = 0;
                while (c >= 0 && !char.IsWhiteSpace((char)c))
                {
                    if ((uint)(c -= 48) >= 10) throw new InvalidDataException();
                    len++;
                    res = checked(res * 10 - c);
                    c = Read();
                }
                if (len == 0) throw new InvalidDataException();
                Back();
                return checked(res * sign);
            }

            public long ReadLong()
            {
                long res = 0;
                int sign = -1;
                int c;
                do { c = Read(); } while (c >= 0 && char.IsWhiteSpace((char)c));
                if (c == '-')
                {
                    sign = -sign;
                    c = Read();
                }
                int len = 0;
                checked
                {
                    while (c >= 0 && !char.IsWhiteSpace((char)c))
                    {
                        if ((uint)(c -= 48) >= 10) throw new InvalidDataException();
                        len++;
                        res = res * 10 - c;
                        c = Read();
                    }
                    if (len == 0) throw new InvalidDataException();
                    Back();
                    return res * sign;
                }
            }

            public double ReadDouble()
            {
                int c;
                do { c = Read(); } while (c >= 0 && char.IsWhiteSpace((char)c));

                int sign = 1;
                if (c == '-')
                {
                    sign = -1;
                    c = Read();
                }

                sb.Length = 0;
                while (c >= 0 && !char.IsWhiteSpace((char)c))
                {
                    sb.Append((char)c);
                    c = Read();
                }

                Back();
                double res = double.Parse(sb.ToString(), CultureInfo.InvariantCulture);
                return res * sign;
            }

            public string ReadLine()
            {
                int c = Read();
                sb.Length = 0;
                while (c != -1 && c != 13 && c != 10)
                {
                    sb.Append((char)c);
                    c = Read();
                }
                if (c == 13)
                {
                    c = Read();
                    if (c != 10) Back();
                }
                return sb.ToString();
            }

            public bool EOF
            {
                get
                {
                    if (Read() == -1) return true;
                    Back();
                    return false;
                }
            }

            public bool SeekEOF
            {
                get
                {
                L0:
                    int c = Read();
                    if (c == -1) return true;
                    if (char.IsWhiteSpace((char)c)) goto L0;
                    Back();
                    return false;
                }
            }
        }

        static void pe()
        {
            Console.WriteLine("???");
            Environment.Exit(0);
        }

        static void re()
        {
            Environment.Exit(55);
        }

        static int nosol()
        {
            Console.WriteLine("ERROR");
            return 0;
        }

        static Stopwatch sw = Stopwatch.StartNew();

        static StringBuilder sb = new StringBuilder();
        static Random rand = new Random(52345235);

        static void Swap<T>(ref T a, ref T b)
        {
            T t = a;
            a = b;
            b = t;
        }

        static int n;
        static int[] j = new int[6];
        static int[,] l = new int[6, 6];
        static int[,] h = new int[6, 6];
        static int[,] a = new int[6, 6];
        static int[,] flow = new int[6, 6];

        static int resultFlow;
        static int resultCost;

        static void per(int v, int w, int q)
        {
            if (q < 0) throw new Exception();

            int j_bak = j[w];

            if (w == n - 1)
            {
                if (q >= l[v, w] && q <= h[v, w])
                {
                    flow[v, w] = q;
                    j[w] = j_bak + q;
                    visit(v + 1);
                }
            }
            else
            {
                for (int i = l[v, w]; i <= h[v, w]; i++)
                {
                    if (i > q) break;
                    if (q - i > 5 * (n - 1 - w)) continue;
                    flow[v, w] = i;
                    j[w] = j_bak + i;
                    per(v, w + 1, q - i);
                }
            }

            flow[v, w] = 0;
            j[w] = j_bak;
        }

        static void visit(int v)
        {
            if (v == n - 1)
            {
                if (j[n - 1] != j[0]) throw new Exception();
                if (j[n - 1] <= resultFlow)
                {
                    int cost = 0;
                    for (v = 0; v < n; v++)
                        for (int w = v + 1; w < n; w++)
                            if (flow[v, w] > 0) cost += a[v, w] + flow[v, w] * flow[v, w];
                    if (j[n - 1] < resultFlow || cost > resultCost) resultCost = cost;
                    resultFlow = j[n - 1];
                }
            }
            else
            {
                per(v, v + 1, j[v]);
            }
        }

        static int Main(string[] args)
        {
            //Console.SetIn(File.OpenText("_input"));
            Parser parser = new Parser();
            while (!parser.SeekEOF)
            {
                n = parser.ReadInt();
                for (int i = 0; i < n * (n - 1) / 2; i++)
                {
                    int v = parser.ReadInt() - 1;
                    int w = parser.ReadInt() - 1;
                    l[v, w] = parser.ReadInt();
                    h[v, w] = parser.ReadInt();
                    a[v, w] = parser.ReadInt();
                }

                resultFlow = int.MaxValue;
                resultCost = 0;
                for (j[0] = 0; j[0] <= 25; j[0]++)
                    visit(0);

                if (resultFlow == int.MaxValue) resultFlow = resultCost = -1;
                Console.WriteLine(resultFlow + " " + resultCost);
            }

            return 0;
        }
    }
}


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

namespace round515
{
  class Point
  {
    public int x, y;

    public Point(int x, int y)
    {
      this.x = x;
      this.y = y;
    }

    public int distance(Point p)
    {
      return Math.Abs(x - p.x) + Math.Abs(y - p.y);
    }
  }

  class MainClass
  {
    public static void Main(string[] args)
    {
      var n = int.Parse(Console.ReadLine());
      var d = new Dictionary<int, List<Point>>();
      for (int i = 0; i < n; ++i)
      {
        var line = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
        int x = line[0];
        int y = line[1];

        int level = Math.Max(x, y);
        if (d.ContainsKey(level))
        {
          d[level].Add(new Point(x, y));
        }
        else
        {
          var list = new List<Point> { new Point(x, y) };
          d.Add(level, list);
        }
      }

      var pp0 = new Point(0, 0);
      var pp1 = pp0;
      long c0 = 0;
      long c1 = 0;
      foreach (var kv in d.OrderBy((kv) => kv.Key))
      {
        var level = kv.Key;
        var list = kv.Value;
        list.Sort((a, b) => {
          if (a.y == b.y)
            return a.x - b.x;
          return b.y - a.y;
        });

        var p0 = list[0];
        var p1 = list[list.Count - 1];

        long nc0 = Math.Min(c0 + p1.distance(pp0) + p1.distance(p0), c1 + p1.distance(pp1) + p1.distance(p0));
        long nc1 = Math.Min(c0 + p0.distance(pp0) + p0.distance(p1), c1 + p0.distance(pp1) + p0.distance(p1));

        c0 = nc0;
        c1 = nc1;

        pp0 = p0;
        pp1 = p1;
      }

      Console.WriteLine(Math.Min(c0, c1));
    }
  }
}


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

namespace SP.Solutions.CodeForces.c338_196_1
{
	public class ProgramC
	{
	    private static long bestRes = long.MaxValue;

		public static void Main()
		{
			checked
			{
			    bestRes = long.MaxValue;
			    int n = int.Parse(Console.ReadLine());
			    var arr = Console.ReadLine().Split(' ').Select(long.Parse).Distinct().ToArray();
                Array.Sort(arr);

			    var primes = GetPrimes();

			    var nodes = new List<Node>();
                for (int i = 0; i < arr.Length; i++)
                {
                    nodes.Add(new Node(arr[i], getFactors(arr[i], primes), arr[i], false, 0));
                }

			    TryBuildTrees(nodes, 0);
                Console.WriteLine(bestRes);
			}
		}

	    private static void TryBuildTrees(List<Node> nodes, int minJ)
	    {
	        var noWay = true;
            for (int j = minJ; j < nodes.Count; j++)
                for (int i = j + 1; i < nodes.Count; i++)
                if (j != i && !nodes[j].HasParent && nodes[i].Rem%nodes[j].N == 0 && !nodes[i].HasParent)
	        {
	            noWay = false;
	            int add = nodes[j].Factors > 1 ? 1 : 0;

	            var r1 = nodes[i].Rem;
	            var add1 = nodes[i].addFactors;

	            nodes[i].Rem = nodes[i].Rem/nodes[j].N;
	            nodes[i].addFactors = nodes[i].addFactors + nodes[j].addFactors + add;
	            nodes[j].HasParent = true;

                TryBuildTrees(nodes, minJ);

                nodes[j].HasParent = false;
                nodes[i].Rem = r1;
                nodes[i].addFactors = add1;
            }
            if (noWay)
	            CalcPrice(nodes);
	    }

	    private static void CalcPrice(List<Node> nodes)
	    {
	        int n = 0;
	        long res = 0;
            foreach (var node in nodes) if (!node.HasParent)
            {
                if (node.Factors > 1) res++;
                res += node.Factors + node.addFactors;
                n++;
            }
	        if (n > 1) res++;
	        bestRes = Math.Min(bestRes, res);
	    }

	    static int getFactors(long n, long[] primes)
        {
            int res = 0;
            int i = 0;
            while (n > 1 && i < primes.Length)
            {
                if (n%primes[i] == 0)
                {
                    res++;
                    n /= primes[i];
                }
                else i++;
            }
	        if (i == primes.Length) res++;
            return res;
        }

        class Node
        {
            public override string ToString()
            {
                return string.Format("HasParent: {0}, N: {1}, Factors: {2}, Rem: {3}", HasParent, N, Factors, Rem);
            }

            public bool HasParent;
            public readonly long N;
            public int Factors;
            public long Rem;
            public int addFactors;

            public Node(long n, int factors, long rem, bool hasParent, int addFactors)
            {
                HasParent = hasParent;
                this.addFactors = addFactors;
                N = n;
                Factors = factors;
                Rem = rem;
            }
        }

	    private static long[] GetPrimes()
	    {
	        const int max = 1000000;
	        var primes = new List<long>(80000);
	        primes.Add(2);
	        var isNotPrime = new bool[max + 1];
            for (int i = 3 ; i<= max ; i+=2) if (!isNotPrime[i])
            {
                primes.Add(i);
                for (int j = i*i; j <= max && j > 0; j += i) isNotPrime[j] = true;
            }
	        return primes.ToArray();
	    }
	}
}


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

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

            var a = Console.ReadLine().Split(' ').Select(short.Parse).ToArray();
             a[2] %= a[0];
            switch (Math.Sign(a[2]))
            {
                case 0: { Console.WriteLine(a[1]); } break;
                case -1: { Console.WriteLine( (a[1]+a[2]<=0)?a[0]+(a[1]+a[2]):a[1]+a[2]); } break;
                case 1: { Console.WriteLine( (a[1]+a[2]<=a[0])?a[1]+a[2]:a[1]+a[2]-a[0]); } break;
            }
        }
    }
}


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

namespace ConsoleApplication1.CodeForces
{
    static class _4032123
    {
        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';
            }
        }
        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);

        class Node
        {
            public int D { get; set; }
            public int F { get; set; }
            public int T { get; set; }
            public long C { get; set; }
        }
        static void Main(String[] args)
        {
            var n = int.Parse(Console.ReadLine().TrimEnd());
            var data = Console.ReadLine().TrimEnd().Split(' ').Select(int.Parse).ToList();
            writer.WriteLine(Math.Max(0, data.Max() - 25));
            writer.Flush();

        }
    }
}


using System;

public class Solution
{
    static void Main(string[] args)
    {
        string[] str = Console.ReadLine().Split(' ');
        int n = int.Parse(str[0]);
        int l = int.Parse(str[1]);
        int r = int.Parse(str[2]);

        int last = 1,
            pos = 0,
            min = 0,
            max = 0;

        for (int i = 0; i < n; i++)
        {
            if (i < l)
                min += last;
            else
                min += 1;
            max += last;

            if (i + 1 < r)
                last = last * 2;
        }

        Console.Write(min);
        Console.Write(" ");
        Console.Write(max);
    }
}


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

namespace CodeforcesTemplate
{
    public static class Permutation
    {
        private static bool Next(ref int[] arr)
        {
            int k, j, l;
            for (j = arr.Length - 2; (j >= 0) && (arr[j] >= arr[j + 1]); j--) { }
            if (j == -1)
            {
                arr = arr.OrderBy(c => c).ToArray();
                return false;
            }
            for (l = arr.Length - 1; (arr[j] >= arr[l]) && (l >= 0); l--) { }
            var tmp = arr[j];
            arr[j] = arr[l];
            arr[l] = tmp;
            for (k = j + 1, l = arr.Length - 1; k < l; k++, l--)
            {
                tmp = arr[k];
                arr[k] = arr[l];
                arr[l] = tmp;
            }
            return true;
        }
        public static IEnumerable<int[]> AllPermutations(int[] arr)
        {
            do yield return arr;
            while (Next(ref arr));
        }
    }

    class Program
    {
        private const string FILENAME = "distance4";

        private const string INPUT = FILENAME + ".in";

        private const string OUTPUT = FILENAME + ".out";

        private static Stopwatch _stopwatch = new Stopwatch();

        private static StreamReader _reader = null;
        private static StreamWriter _writer = null;

        private static string[] _curLine;
        private static int _curTokenIdx;

        private static char[] _whiteSpaces = new char[] { ' ', '\t', '\r', '\n' };

        private static string ReadNextToken()
        {
            if (_curTokenIdx >= _curLine.Length)
            {
                //Read next line
                string line = _reader.ReadLine();
                if (line != null)
                    _curLine = line.Split(_whiteSpaces, StringSplitOptions.RemoveEmptyEntries);
                else
                    _curLine = new string[] { };
                _curTokenIdx = 0;
            }

            if (_curTokenIdx >= _curLine.Length)
                return null;

            return _curLine[_curTokenIdx++];
        }

        private static int ReadNextInt()
        {
            return int.Parse(ReadNextToken());
        }

        private static void RunTimer()
        {
#if (DEBUG)

            _stopwatch.Start();

#endif
        }

        private static void Main(string[] args)
        {

#if (DEBUG)
            double before = GC.GetTotalMemory(false);
#endif

            long a = long.Parse(Console.ReadLine());
            long b = long.Parse(Console.ReadLine());

            char[] aChar = ("" + a).ToCharArray();
            char[] bChar = ("" + b).ToCharArray();

            if (aChar.Length < bChar.Length)
            {
                Array.Sort(aChar);
                for (int i = aChar.Length - 1; i >= 0; i--)
                {
                    Console.Write(aChar[i]);
                }

                Console.WriteLine();

                return;
            }

            int[] aDigit = new int[10];
            int[] bDigit = new int[10];
            foreach (char ch in aChar)
            {
                aDigit[ch - '0']++;
            }

            foreach (char ch in bChar)
            {
                bDigit[ch - '0']++;
            }

            bool same = true;

            for (int i = 0; i < 10; i++)
            {
                if (aDigit[i] != bDigit[i])
                {
                    same = false;
                }
            }

            if (same)
            {
                Console.WriteLine(b);
                return;
            }

            long answer = 0;

            for (int divide = 0; divide < aChar.Length; divide++)
            {
                if (divide >= 1)
                {
                    if (aDigit[bChar[divide - 1] - '0'] == 0)
                    {
                        break;
                    }

                    aDigit[bChar[divide - 1] - '0']--;
                }

                StringBuilder sb = new StringBuilder();

                for (int i = 0; i < divide; i++)
                {
                    sb.Append(bChar[i]);
                }

                int usedLower = -1;
                {
                    for (int d = (bChar[divide] - '0') - 1; d >= (divide == 0 ? 1 : 0); d--)
                    {
                        if (aDigit[d] > 0)
                        {
                            usedLower = d; break;
                        }
                    }
                }
                if (usedLower < 0)
                {
                    continue;
                }

                sb.Append((char)('0' + usedLower));

                aDigit[usedLower]--;

                for (int i = divide + 1; i < aChar.Length; i++)
                {
                    for (int d = 9; d >= 0; d--)
                    {
                        for (int x = 0; x < aDigit[d] && i < aChar.Length; x++, i++)
                        {
                            sb.Append((char)('0' + d));
                        }
                    }
                }

                aDigit[usedLower]++;

                answer = Math.Max(answer, long.Parse(sb.ToString()));
            }

            Console.WriteLine(answer);

#if (DEBUG)
            _stopwatch.Stop();

            double after = GC.GetTotalMemory(false);

            double consumedInMegabytes = (after - before) / (1024 * 1024);

            Console.WriteLine($"Time elapsed: {_stopwatch.Elapsed}");

            Console.WriteLine($"Consumed memory (MB): {consumedInMegabytes}");

            Console.ReadKey();
#endif

        }

        private static int CountLeadZeros(string source)
        {
            int countZero = 0;

            for (int i = source.Length - 1; i >= 0; i--)
            {
                if (source[i] == '0')
                {
                    countZero++;
                }

                else
                {
                    break;
                }

            }

            return countZero;
        }

        private static string ReverseString(string source)
        {
            char[] reverseArray = source.ToCharArray();

            Array.Reverse(reverseArray);

            string reversedString = new string(reverseArray);

            return reversedString;
        }

        private static int[] CopyOfRange(int[] src, int start, int end)
        {
            int len = end - start;
            int[] dest = new int[len];
            Array.Copy(src, start, dest, 0, len);
            return dest;
        }

        private static string StreamReader()
        {

            if (_reader == null)
                _reader = new StreamReader(INPUT);
            string response = _reader.ReadLine();
            if (_reader.EndOfStream)
                _reader.Close();
            return response;

        }

        private static void StreamWriter(string text)
        {

            if (_writer == null)
                _writer = new StreamWriter(OUTPUT);
            _writer.WriteLine(text);

        }

        private static int BFS(int start, int end, int[,] arr)
        {
            Queue<KeyValuePair<int, int>> queue = new Queue<KeyValuePair<int, int>>();
            List<bool> visited = new List<bool>();
            for (int i = 0; i < arr.GetLength(0); i++)
            {
                visited.Add(false);
            }

            queue.Enqueue(new KeyValuePair<int, int>(start, 0));
            KeyValuePair<int, int> node;
            int level = 0;
            bool flag = false;

            while (queue.Count != 0)
            {
                node = queue.Dequeue();
                if (node.Key == end)
                {
                    return node.Value;
                }
                flag = false;
                for (int i = 0; i < arr.GetLength(0); i++)
                {

                    if (arr[node.Key, i] == 1)
                    {
                        if (visited[i] == false)
                        {
                            if (!flag)
                            {
                                level = node.Value + 1;
                                flag = true;
                            }
                            queue.Enqueue(new KeyValuePair<int, int>(i, level));
                            visited[i] = true;
                        }
                    }
                }

            }
            return 0;

        }

        private static void Write(string source)
        {
            File.WriteAllText(OUTPUT, source);
        }

        private static string ReadString()
        {
            return File.ReadAllText(INPUT);
        }

        private static void WriteStringArray(string[] source)
        {
            File.WriteAllLines(OUTPUT, source);
        }

        private static string[] ReadStringArray()
        {
            return File.ReadAllLines(INPUT);
        }

        private static int[] GetIntArray()
        {
            return ReadString().Split(' ').Select(int.Parse).ToArray();
        }

        private static double[] GetDoubleArray()
        {
            return ReadString().Split(' ').Select(double.Parse).ToArray();
        }

        private static int[,] ReadINT2XArray(List<string> lines)
        {
            int[,] arr = new int[lines.Count, lines.Count];

            for (int i = 0; i < lines.Count; i++)
            {
                int[] row = lines[i].Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries).Select(int.Parse).ToArray();

                for (int j = 0; j < lines.Count; j++)
                {
                    arr[i, j] = row[j];
                }
            }

            return arr;
        }
    }
}


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

namespace WatchingFootball
{
    class Program
    {
        private static int a;

        private static int b;

        private static int c;

        static void Main(string[] args)
        {
            int[] values = Console.ReadLine().Split(' ').Select(s => Convert.ToInt32(s)).ToArray();
            a = values[0];
            b = values[1];
            c = values[2];

            int result = Solve();
            Console.Out.WriteLine(result);
        }

        private static int Solve()
        {
            return (int) Math.Max(0, Math.Ceiling((0.0 + a - b) * c / b));
        }
    }
}


using System;
using System.Collections.Generic;

// Codeforces problem 189A "Разрежь ленточку"
// http://codeforces.com/problemset/problem/189/A
namespace _189_A
{
	class Program
	{
		static void Main(string[] args)
		{
			#region Read data
			string[] tmp = Console.ReadLine().Split();
			int length = Convert.ToInt32(tmp[0]);
			List<int> abc = new List<int>();
			for (int i = 1; i < tmp.Length; i++)
			{
				abc.Add(Convert.ToInt32(tmp[i]));
			}
			abc.Sort();
			int a = abc[0];
			int b = abc[1];
			int c = abc[2];
			#endregion
			#region Process data
			int result = 0;
			for (int z = 0; z <= length / c; z++)
			{
				for (int y = 0; y <= length / b; y++)
				{
					if ((length - y * b - z * c) % a == 0)
					{
						int x = (length - y * b - z * c) / a;
						if (result < x + y + z)
						{
							result = x + y + z;
						}
					}
				}
			}
			#endregion
			#region Write results
			Console.WriteLine(result);
			Console.ReadLine();
			#endregion
		}
	}
}


using System;
using System.Numerics;
namespace Program {
    class Program {
        static int N;
        static void Main(string[] args) {
            var n = ri();
            long m = Convert.ToInt64(Math.Floor(Math.Sqrt(n)));
            var iter = 0;
            for (int i = 1; i <= m; i++) {
                if (n % i == 0)
                    iter += 2;
            }
            if (m*m == n)
                iter--;
            Console.WriteLine(iter);
        }

        static (BigInteger, BigInteger, BigInteger, BigInteger) r4bi() {
            var i = Console.ReadLine().Split(' ');
            return (BigInteger.Parse(i[0]), BigInteger.Parse(i[1]), BigInteger.Parse(i[2]), BigInteger.Parse(i[3]));
        }
        static int[] ris() {
            return Array.ConvertAll(Console.ReadLine().Split(' '), i => Int32.Parse(i));
        }

        static long ri() {
            var i = Console.ReadLine();
            return Int64.Parse(i);
        }
        static (int, int) r2i() {
            var i = Console.ReadLine().Split(' ');
            return (Int32.Parse(i[0]), Int32.Parse(i[1]));
        }
        static (int, int, int) r3i() {
            var i = Console.ReadLine().Split(' ');
            return (Int32.Parse(i[0]), Int32.Parse(i[1]), Int32.Parse(i[2]));
        }
    }
}


using System;
using System.Collections.Generic;

namespace Day_23
{
    class Program
    {
        static Int64 gcd(Int64 a, Int64 b)
        {
            if (a == 0)
                return b;
            return gcd(b % a, a);
        }
        static Int64 lcm(Int64 a, Int64 b)
        {
            return (a * b) / gcd(a, b);
        }
        public static List<Int64> SieveOfEratosthenes(Int64 n)
        {

            /*
             *
             *
             */

            Dictionary<Int64, Int64> keyValuePairs = new Dictionary<Int64, Int64>();

            for (Int64 p = 2; p * p <= n; p++)
            {
                // If prime[p] is not changed,
                // then it is a prime
                if (!keyValuePairs.ContainsKey(p))
                {
                    //// Update all multiples of p
                    //for (Int64 i = p * p; i <= n; i += p)
                    //    prime[i] = false;
                    keyValuePairs.Add(p, 1);
                }
            }
            List<Int64> primes = new List<Int64>();
            foreach (Int64 key in keyValuePairs.Keys) primes.Add(key);
            return primes;
        }

        static void Main(string[] args)
        {
            Int64 X = Convert.ToInt64(Console.ReadLine());
            if (X == 1)
            {
                Console.WriteLine("1 1");
                return;
            }
            SortedDictionary<Int64, Int64> keyValuePairs = new SortedDictionary<Int64, Int64>();
            Int64 last_added = 1;

            //List<int> banned_primes = new List<int>();

            //if (X % 2 != 0) banned_primes.Add(2);
            //if (X % 3 != 0) banned_primes.Add(3);
            //if (X % 5 != 0) banned_primes.Add(5);
            //if (X % 7 != 0) banned_primes.Add(7);

            keyValuePairs.Add(1, X);
            List<Int64> primes = SieveOfEratosthenes(X);
            foreach(Int64 i in primes)
            {

            //}

            //for (Int64 i = 2; i < 10; i++)
            //{
            //    bool found = false;
            //    foreach (int ix in banned_primes)
            //    {
            //        if (i % ix == 0)
            //        {
            //            found = true;
            //            break;
            //        }
            //    }
            //    if (found) continue;

                //while (i <= X)
                //{
                    if (X % i == 0)
                    {
                        if (keyValuePairs.ContainsKey(i) || keyValuePairs.ContainsKey(X / i))
                        {
                            //i += i;
                            continue;
                        }
                        else
                        {
                            if (lcm(i, X / i) == X)
                            {
                                keyValuePairs.Add(i, X / i);
                                last_added = i;
                            }
                        }
                    }
                //    i += i;
                //}
            }
            Console.WriteLine($"{last_added} {keyValuePairs[last_added]}");
        }
    }
}


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

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

        public FastScanner(Stream stream) : base(stream)
        {
            _line = null;
            _iterator = 0;
        }
        public string NextToken()
        {
            if (_line == null || _iterator >= _line.Length)
            {
                _line = base.ReadLine().Split(' ');
                _iterator = 0;
            }
            if (_line.Count() == 0) throw new IndexOutOfRangeException("Input string is empty");
            return _line[_iterator++];
        }
        public int NextInt()
        {
            return Convert.ToInt32(NextToken());
        }
        public long NextLong()
        {
            return Convert.ToInt64(NextToken());
        }
        public float NextFloat()
        {
            return float.Parse(NextToken());
        }
        public double NextDouble()
        {
            return Convert.ToDouble(NextToken());
        }
    }
    class Vacations363
    {
        public static void Main(string[] args)
        {
            using (FastScanner fs = new FastScanner(new BufferedStream(Console.OpenStandardInput())))
            using (StreamWriter writer = new StreamWriter(new BufferedStream(Console.OpenStandardOutput())))
            {
                int n = fs.NextInt(), inf = (int)1e8;
                int[] a = Array.ConvertAll(fs.ReadLine().Split(), Convert.ToInt32);
                int r = 1;
                int g = a[0] == 3 || a[0] == 2 ? 0 : inf;
                int c = a[0] == 3 || a[0] == 1 ? 0 : inf;
                for (int i = 1; i < n; i++)
                {
                    int ng = Math.Min(c, r) + (a[i] == 3 || a[i] == 2 ? 0 : inf);
                    int nc = Math.Min(r, g) + (a[i] == 3 || a[i] == 1 ? 0 : inf);
                    int nr = Math.Min(r, Math.Min(g, c)) + 1;
                    r = nr;
                    g = ng;
                    c = nc;
                }
                writer.WriteLine(Math.Min(r, Math.Min(g, c)));
            }
        }
    }
}


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

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] number = Array.ConvertAll(Console.ReadLine().Split(' '), x => int.Parse(x));

            //Get next prime number
            int num = number[0];
            while (true)
            {
                num++;
                if(IsPrime(num))
                {
                    break;
                }
            }

            if (num == number[1])
                Console.WriteLine("YES");
            else
                Console.WriteLine("NO");
        }

        public static bool IsPrime(int number)
        {
            if (number == 1) return false;
            if (number == 2) return true;
            if (number % 2 == 0) return false;

            var boundary = (int)Math.Floor(Math.Sqrt(number));

            for (int i = 3; i <= boundary; i += 2)
            {
                if (number % i == 0) return false;
            }

            return true;
        }
    }
}


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)
    {
        int N, M;
        sc.Make(out N, out M);
        if (N > M + 1) Fail(0);
        if (N == 2) Fail(0);
        ModInt.Build(M + 1);
        ModInt res = 0;

        for(int i = 0; i < N - 2; i++)
        {
            res += ModInt.Comb(N - 3, i);
        }
        res *= ModInt.Comb(M, N - 1);
        WriteLine(res*(N-2));
    }
}

public struct ModInt
{
    //public const long MOD = (int)1e9 + 7;
    public const long MOD = 998244353;
    public long Value { get; set; }
    public ModInt(long n = 0) { Value = n; }
    private static ModInt[] fac;//階乗
    private static ModInt[] inv;//逆数
    private static ModInt[] facinv;//1/(i!)
    public override string ToString() => Value.ToString();
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public static ModInt operator +(ModInt l, ModInt r)
    {
        l.Value += r.Value;
        if (l.Value >= MOD) l.Value -= MOD;
        return l;
    }
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public static ModInt operator -(ModInt l, ModInt r)
    {
        l.Value -= r.Value;
        if (l.Value < 0) l.Value += MOD;
        return l;
    }
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public static ModInt operator *(ModInt l, ModInt r) => new ModInt(l.Value * r.Value % MOD);
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public static ModInt operator /(ModInt l, ModInt r) => l * Pow(r, MOD - 2);
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public static implicit operator long(ModInt l) => l.Value;
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public static implicit operator ModInt(long n)
    {
        n %= MOD; if (n < 0) n += MOD;
        return new ModInt(n);
    }

    public static ModInt Pow(ModInt m, long n)
    {
        if (n == 0) return 1;
        if (n % 2 == 0) return Pow(m * m, n >> 1);
        else return Pow(m * m, n >> 1) * m;
    }

    public static void Build(int n)
    {
        fac = new ModInt[n + 1];
        facinv = new ModInt[n + 1];
        inv = new ModInt[n + 1];
        inv[1] = 1;
        fac[0] = fac[1] = 1;
        facinv[0] = facinv[1] = 1;
        for (var i = 2; i <= n; i++)
        {
            fac[i] = fac[i - 1] * i;
            inv[i] = MOD - inv[MOD % i] * (MOD / i);
            facinv[i] = facinv[i - 1] * inv[i];
        }
    }
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public static ModInt Fac(ModInt n) => fac[n];
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public static ModInt Inv(ModInt n) => inv[n];
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public static ModInt FacInv(ModInt n) => facinv[n];
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public static ModInt Comb(ModInt n, ModInt r)
    {
        if (n < r) return 0;
        if (n == r) return 1;
        var calc = fac[n];
        calc = calc * facinv[r];
        calc = calc * facinv[n - r];
        return calc;
    }
}
#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) == 1) { 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) == -1) { 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; }
    public static T[] Shuffle<T>(this IList<T> A) { T[] rt = A.ToArray(); Random rnd = new Random(); for (int i = rt.Length - 1; i >= 1; i--) swap(ref rt[i], ref rt[rnd.Next(i + 1)]); return rt; }
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    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; }
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    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 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 (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.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
//using System.Numerics;
using System.Text;
using System.Threading;

// (づ°ω°)づﾐe★゜・。。・゜゜・。。・゜☆゜・。。・゜゜・。。・゜
public class Solver
{
    void Solve()
    {
        int n = ReadInt();
        int t = ReadInt();
        var a = ReadIntArray();

        var list = new List<int>(a.Distinct());
        list.Sort();
        for (int i = 0; i < n; i++)
            a[i] = list.BinarySearch(a[i]);

        int m = list.Count;
        int mt = Math.Min(m, t);
        var pdp = new int[mt + 1][];
        var dp = new int[m];
        for (int i = 0; i <= mt; i++)
        {
            for (int j = 0; j < n; j++)
            {
                int v = dp[a[j]] + 1;
                for (int k = a[j]; k < m; k++)
                    dp[k] = Math.Max(dp[k], v);
            }
            pdp[i] = (int[])dp.Clone();
        }

        var sdp = new int[mt + 1][];
        dp = new int[n];
        for (int i = 0; i <= mt; i++)
        {
            for (int j = n - 1; j >= 0; j--)
            {
                int v = dp[a[j]] + 1;
                for (int k = 0; k <= a[j]; k++)
                    dp[k] = Math.Max(dp[k], v);
            }
            sdp[i] = (int[])dp.Clone();
        }

        var cnt = new int[m];
        foreach (int aa in a)
            cnt[aa]++;

        int ans = 0;
        for (int mid = 0; mid < m; mid++)
            for (int left = 0; left <= mt; left++)
                for (int right = 0; right <= mt && left + right <= t; right++)
                    ans = Math.Max(ans, (left == 0 ? 0 : pdp[left - 1][mid]) + (right == 0 ? 0 : sdp[right - 1][mid]) + cnt[mid] * (t - left - right));

        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());
        //reader = new StreamReader("transform.in");
        //writer = new StreamWriter("transform.out");
#endif
        try
        {
            //var thread = new Thread(new Solver().Solve, 1024 * 1024 * 128);
            //thread.Start();
            //thread.Join();
            new Solver().Solve();
        }
        catch (Exception ex)
        {
            Console.WriteLine(ex);
#if DEBUG
#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
}


#define Online

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

namespace CF
{
    delegate double F(double x);
    delegate decimal Fdec(decimal x);

    partial class Program
    {

        static void Main(string[] args)
        {

#if FileIO
            StreamReader sr = new StreamReader("nosimple.in");
            StreamWriter sw = new StreamWriter("nosimple.out");
            Console.SetIn(sr);
            Console.SetOut(sw);
#endif

            B();

#if Online
            Console.ReadLine();
#endif

#if FileIO
            sr.Close();
            sw.Close();
#endif
        }

        static void A()
        {

        }

        static void B()
        {
            long a, b, c, d;
            ReadArray(' ');
            a = NextLong();
            b = NextLong();
            c = NextLong();
            d = NextLong();
            long g1 = MyMath.GCD(a, b);
            long g2 = MyMath.GCD(c, d);
            a /= g1;
            b /= g1;
            c /= g2;
            d /= g2;
            long i = 1;
            while (a * i < c || b * i < d)
                i++;

            a *= i;
            b *= i;
            long p, q;
            if (a * b * d >= c * b * b)
            {
                p = a * b * d - c * b * b;
                q = d * a * b;
                long g3 = MyMath.GCD(p, q);
                p /= g3;
                q /= g3;
            }
            else
            {
                p = a * b * c - d * a * a;
                q = c * a * b;
                long g4 = MyMath.GCD(p, q);
                p /= g4;
                q /= g4;
            }
            Console.WriteLine(p + "/" + q);
        }

        static void C()
        {

        }

        static void D()
        {

        }

        static void E()
        {

        }

        static void TestGen()
        {

        }

    }

    public static class MyMath
    {
        public static long BinPow(long a, long n, long mod)
        {
            long res = 1;
            while (n > 0)
            {
                if ((n & 1) == 1)
                {
                    res = (res * a) % mod;
                }
                a = (a * a) % mod;
                n >>= 1;
            }
            return res;
        }

        public static long GCD(long a, long b)
        {
            while (b != 0) b = a % (a = b);
            return a;
        }

        public static int GCD(int a, int b)
        {
            while (b != 0) b = a % (a = b);
            return a;
        }

        public static long LCM(long a, long b)
        {
            return (a * b) / GCD(a, b);
        }

        public static int LCM(int a, int b)
        {
            return (a * b) / GCD(a, b);
        }
    }

    static class ArrayUtils
    {
        public static int BinarySearch(int[] a, int val)
        {
            int left = 0;
            int right = a.Length - 1;
            int mid;

            while (left < right)
            {
                mid = left + ((right - left) >> 1);
                if (val <= a[mid])
                {
                    right = mid;
                }
                else
                {
                    left = mid + 1;
                }
            }

            if (a[left] == val)
                return left;
            else
                return -1;
        }

        public static double Bisection(F f, double left, double right, double eps)
        {
            double mid;
            while (right - left > eps)
            {
                mid = left + ((right - left) / 2d);
                if (Math.Sign(f(mid)) != Math.Sign(f(left)))
                    right = mid;
                else
                    left = mid;
            }
            return (left + right) / 2d;
        }

        public static decimal TernarySearchDec(Fdec f, decimal eps, decimal l, decimal r, bool isMax)
        {
            decimal m1, m2;
            while (r - l > eps)
            {
                m1 = l + (r - l) / 3m;
                m2 = r - (r - l) / 3m;
                if (f(m1) < f(m2))
                    if (isMax)
                        l = m1;
                    else
                        r = m2;
                else
                    if (isMax)
                        r = m2;
                    else
                        l = m1;
            }
            return r;
        }

        public static double TernarySearch(F f, double eps, double l, double r, bool isMax)
        {
            double m1, m2;
            while (r - l > eps)
            {
                m1 = l + (r - l) / 3d;
                m2 = r - (r - l) / 3d;
                if (f(m1) < f(m2))
                    if (isMax)
                        l = m1;
                    else
                        r = m2;
                else
                    if (isMax)
                        r = m2;
                    else
                        l = m1;
            }
            return r;
        }

        public static void Merge<T>(T[] A, int p, int q, int r, T[] L, T[] R, Comparison<T> comp)
        {
            for (int i = p; i <= q; i++)
                L[i] = A[i];
            for (int i = q + 1; i <= r; i++)
                R[i] = A[i];

            for (int k = p, i = p, j = q + 1; k <= r; k++)
            {
                if (i > q)
                {
                    for (; k <= r; k++, j++)
                        A[k] = R[j];
                    return;
                }
                if (j > r)
                {
                    for (; k <= r; k++, i++)
                        A[k] = L[i];
                    return;
                }
                if (comp(L[i], R[j]) <= 0)
                {
                    A[k] = L[i];
                    i++;
                }
                else
                {
                    A[k] = R[j];
                    j++;
                }
            }
        }

        public static void Merge_Sort<T>(T[] A, int p, int r, T[] L, T[] R, Comparison<T> comp)
        {
            if (p >= r) return;
            int q = p + ((r - p) >> 1);
            Merge_Sort(A, p, q, L, R, comp);
            Merge_Sort(A, q + 1, r, L, R, comp);
            Merge(A, p, q, r, L, R, comp);
        }

        public static void Merge<T>(T[] A, int p, int q, int r, T[] L, T[] R) where T : IComparable<T>
        {
            for (int i = p; i <= q; i++)
                L[i] = A[i];
            for (int i = q + 1; i <= r; i++)
                R[i] = A[i];

            for (int k = p, i = p, j = q + 1; k <= r; k++)
            {
                if (i > q)
                {
                    for (; k <= r; k++, j++)
                        A[k] = R[j];
                    return;
                }
                if (j > r)
                {
                    for (; k <= r; k++, i++)
                        A[k] = L[i];
                    return;
                }
                if (L[i].CompareTo(R[j]) <= 0)
                {
                    A[k] = L[i];
                    i++;
                }
                else
                {
                    A[k] = R[j];
                    j++;
                }
            }
        }

        public static void Merge_Sort<T>(T[] A, int p, int r, T[] L, T[] R) where T : IComparable<T>
        {
            if (p >= r) return;
            int q = p + ((r - p) >> 1);
            Merge_Sort(A, p, q, L, R);
            Merge_Sort(A, q + 1, r, L, R);
            Merge(A, p, q, r, L, R);
        }

        public static void Merge_Sort1<T>(T[] A, int p, int r, T[] L, T[] R) where T : IComparable<T>
        {
            int k = 1;
            while (k < r - p + 1)
            {
                int i = 0;
                while (i < r)
                {
                    int _r = Math.Min(i + 2 * k - 1, r);
                    int q = Math.Min(i + k - 1, r);
                    Merge(A, i, q, _r, L, R);
                    i += 2 * k;
                }
                k <<= 1;
            }
        }

        public static void Merge_Sort1<T>(T[] A, int p, int r, T[] L, T[] R, Comparison<T> comp)
        {
            int k = 1;
            while (k < r - p + 1)
            {
                int i = 0;
                while (i < r)
                {
                    int _r = Math.Min(i + 2 * k - 1, r);
                    int q = Math.Min(i + k - 1, r);
                    Merge(A, i, q, _r, L, R, comp);
                    i += 2 * k;
                }
                k <<= 1;
            }
        }

        static void Shake<T>(T[] a)
        {
            Random rnd = new Random(Environment.TickCount);
            T temp;
            int b;
            for (int i = 0; i < a.Length; i++)
            {
                b = rnd.Next(i, a.Length);
                temp = a[b];
                a[b] = a[i];
                a[i] = temp;
            }
        }
    }

    partial class Program
    {
        static string[] tokens;
        static int cur_token = 0;

        static void ReadArray(char sep)
        {
            cur_token = 0;
            tokens = Console.ReadLine().Split(sep);
        }

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

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

        static int NextInt()
        {
            return int.Parse(tokens[cur_token++]);
        }

        static long NextLong()
        {
            return long.Parse(tokens[cur_token++]);
        }

        static double NextDouble()
        {
            return double.Parse(tokens[cur_token++]);
        }

        static decimal NextDecimal()
        {
            return decimal.Parse(tokens[cur_token++]);
        }

        static string NextToken()
        {
            return tokens[cur_token++];
        }

        static string ReadLine()
        {
            return Console.ReadLine();
        }
    }
}


using System;

namespace Ejercicio5
{
    class Program
    {
        static void Main(string[] args)
        {
            double n;
            double k;
            int numberNotebooks;
            string input;
            string[] inputList;

            input = Console.ReadLine();
            inputList = input.Split(' ');

            n = Convert.ToDouble(inputList[0]);
            k = Convert.ToDouble(inputList[1]);

            if (n>=1 && k<=Math.Pow(10, 8))
            {
                numberNotebooks = getNumberOfSheets(n, k);

                Console.WriteLine(numberNotebooks);
            }
        }

        public static int getNumberOfSheets(double n, double k)
        {
            int neededSheets;
            int red;
            int green;
            int blue;

            red = (int)Math.Ceiling(Convert.ToDecimal((2 * n) / k));
            green = (int)Math.Ceiling(Convert.ToDecimal((5 * n) / k));
            blue = (int)Math.Ceiling(Convert.ToDecimal((8 * n) / k));

            neededSheets = red + green + blue;

            return neededSheets;
        }
    }
}


using System;

public static class Program{
    static int Ri(){return int.Parse(Console.ReadLine());}

    public static void solve()
    {
        int n = Ri();
        long ans = (long)(Math.Pow(2,n)-1);
        Console.WriteLine(ans);

    }
    public static void Main()
    {
        int TestCase = Ri();
        while (TestCase>0){
            solve();
            TestCase--;
        }
    }
}


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

namespace ConsoleApplication3
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] c = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
            int n = c[0];
            int m = c[1];
            int k = c[2];
            if (n == m) {
                Console.WriteLine(1);
                return;
            }
            if (n == m-1)
            {
                Console.WriteLine(2);
                return;
            }
            if (n == 1)
            {
                Console.WriteLine(m);
                return;
            }
            long l = 1;
            long r = m;
            while (r-l>1) {
                long mid =l + (r - l) / 2;
                long s1 = 0, s2 = 0;
                if (k > mid){
                    s1 = mid * (mid - 1) / 2 + k - mid;
                }
                else {
                    s1 = (mid - k + mid) * (k - 1) / 2;
                }
                s1 = k == 1 ? 0 : s1;
                if (n - k > mid - 1)
                {
                    s2 = mid * (mid - 1) / 2 + n - k - mid + 1;
                }
                else
                {
                    s2 = (mid - n + k + mid - 1) * (n - k) / 2;
                }
                s2 = k == n ? 0 : s2;

                long s = s1 + s2 + mid;
                if (s > m) r= mid; else l = mid;
            }
            Console.WriteLine(l);
        }
    }
}