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

namespace ConsoleApplication1
{
    class Program
    {
        static void Sum854b()
        {
/*

B. Максим покупает квартиру

ограничение по времени на тест:1 секунда

ограничение по памяти на тест:512 мегабайт

ввод:стандартный ввод

вывод:стандартный вывод

Максим хочет купить квартиру в модном многоквартирном доме на Линейном проспекте города Мегаполиса. В этом доме n квартир, пронумерованных от 1 до n и расположенных в один ряд.
 * Две квартиры являются соседними, если их номера различаются ровно на 1. Некоторые квартиры могут быть уже заселёнными, остальные свободны и их можно купить.

Максим часто ходит в гости к соседям, поэтому квартира является для него подходящей, если она свободна и есть хотя бы одна заселённая квартира, соседняя с ней.
 * Максим знает, что в доме заселено k квартир, но какие именно, он пока не знает.

Определите, каким может быть минимальное и максимальное число квартир, подходящих для Максима.

Входные данные

В единственной строке входных данных содержатся два целых числа n и k (1 ≤ n ≤ 109, 0 ≤ k ≤ n).

Выходные данные

Выведите минимально возможное и максимально возможное количество подходящих для Максима квартир.

Пример

Входные данные
6 3

Выходные данные
1 3

Примечание

В примере из условия минимальное количество подходящих для Максима квартир достигается, если, например, заселены квартиры с номерами 1, 2 и 3,
 * тогда подходит только квартира номер 4. Максимальное же количество достигается если, например, заселены квартиры с номерами 1, 3, 5, тогда подходят квартиры с номерами 2, 4 и 6.

 */
            string st = Console.ReadLine().Trim();
            Char[] ch = new Char[] { ' ' };
            int[] nk= st.Split(ch).Select(int.Parse).ToArray();
            int res0; // миннимальное количество
            int res1; // максимальное количество
            int tmp;
            if ((nk[1]==nk[0]) || (nk[1]==0)) {
                res0 = 0;
            } else {
                res0 = 1; // 1 в любом другом случае тк они идут подряд
            }
            res1 = nk[1] * 2 < nk[0] - nk[1] ? nk[1] * 2 : nk[0] - nk[1];
            Console.Write("{0} {1}",res0,res1 );

                //все заселены или ни одна не заселена - не подходят
        }
        static void Main(string[] args)
        {
//            SumsCodeForces smc = new SumsCodeForces();
//            smc.Sum429b() ;
            Sum854b();
            Console.ReadLine();
        }
    }
}


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

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

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

            writer.Write(k == 0 || k == n ? "0 " : "1 ");

            writer.WriteLine(Math.Min(n - k, 2*k));
            writer.Flush();
        }

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


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

public class Program
{
    string go(int k, char[] a)
    {
        bool[] used = new bool[k];
        for (int c = 0; c < k; ++c) used[c] = false;

        int n = a.Length;
        for (int c = 0; c < n; ++c)
            if (a[c] != '?') used[a[c] - 'a'] = true;

        int i = 0, j = n - 1;
        for (; i < j; ++i, --j)
        {
            if (a[i] != '?' && a[j] != '?' && a[i] != a[j]) return "IMPOSSIBLE";
            if (a[i] != '?')
            {
                a[j] = a[i];
                continue;
            }
            if (a[j] != '?')
            {
                a[i] = a[j];
                continue;
            }
        }

        for (; j >= 0 && i < n; ++i, --j)
        {
            if (a[i] != '?') continue;

            int c = k - 1;
            while (c >= 0 && used[c]) --c;

            if (c < 0) c = 0;
            a[i] = a[j] = (char)(c + 'a');
            used[c] = true;
        }

        for (int c = 0; c < k; ++c)
            if (!used[c]) return "IMPOSSIBLE";

        return new string(a);
    }

    void doit()
    {
        int k = int.Parse(Console.ReadLine());
        char[] a = Console.ReadLine().ToCharArray();
        Console.WriteLine(go(k, a));
    }

    public static void Main(string[] args)
    {
        (new Program()).doit();
    }
}


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

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

namespace _55c_
{
    class Program
    {
        static string _inputFilename = "input.txt";
        static string _outputFilename = "output.txt";
        static bool _useFileInput = false;

        static void Main(string[] args)
        {
            StreamWriter file = null;
#if DEBUG
			Console.SetIn(getInput());
#else
            if (_useFileInput)
            {
                Console.SetIn(File.OpenText(_inputFilename));
                file = new StreamWriter(_outputFilename);
                Console.SetOut(file);
            }
#endif

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

        static void solution()
        {
            #region SOLUTION
            var k = readInt();
            var s = Console.ReadLine();
            var ex = new int[26];
            for (int i = 0; i < s.Length; i++)
            {
                if (s[i] == '?')
                {
                    continue;
                }

                var next = s[i] - 97;
                if (next >= k)
                {
                    Console.WriteLine("IMPOSSIBLE");
                    return;
                }

                ex[next]++;
            }

            var free = 0;
            for (int i = 0; i < s.Length / 2; i++)
            {
                var qr = s.Length - 1 - i;
                if (s[i] == '?' && s[qr] == '?')
                {
                    free++;
                }
            }

            if (s.Length % 2 == 1 && s[s.Length / 2] == '?')
            {
                free++;
            }

            var needed = 0;
            for (int i = 0; i < k; i++)
            {
                if (ex[i] == 0)
                {
                    needed++;
                }
            }

            var ans = new int[s.Length];
            for (int i = 0; i < s.Length; i++)
            {
                ans[i] = s[i] != '?' ? s[i] - 97 : -1;
            }

            for (int i = 0; i < s.Length / 2; i++)
            {
                var qr = s.Length - 1 - i;
                if (s[i] != '?' && s[qr] != '?' && s[i] != s[qr])
                {
                    Console.WriteLine("IMPOSSIBLE");
                    return;
                }

                if (s[i] != '?' && s[qr] != '?')
                {
                    //ans[i] = s[i];
                    continue;
                }

                if (s[i] == '?' && s[qr] == '?')
                {
                    var tos = getFirst(ex, k, i, needed, free);
                    free--;
                    if (ex[tos] == 0)
                    {
                        needed--;
                    }

                    ex[tos]++;
                    ans[i] = tos;
                    ans[qr] = tos;

                    continue;
                }

                var need = -1;
                if (s[i] != '?')
                {
                    need = s[i] - 97;
                }
                else if (s[qr] != '?')
                {
                    need = s[qr] - 97;
                }

                ex[need]++;
                ans[i] = need;
                ans[qr] = need;
            }

            if (s.Length % 2 == 1)
            {
                var mid = s.Length / 2;
                if (s[mid] == '?')
                {
                    var tos = getFirst(ex, k, mid, needed, free);

                    ex[tos]++;
                    ans[mid] = tos;
                }
            }

            for (int i = 0; i < k; i++)
            {
                if (ex[i] == 0)
                {
                    Console.WriteLine("IMPOSSIBLE");
                    return;
                }
            }

            var sb = new StringBuilder();
            for (int i = 0; i < ans.Length; i++)
            {
                sb.Append((char)(ans[i] + 97));
            }

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

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

        static int getFirst(int[] counts, int k, int i, int needed, int free)
        {
            if (free > needed)
            {
                return 0;
            }

            var found = -1;
            for (int j = 0; j < 26; j++)
            {
                if (j >= k)
                {
                    break;
                }

                if (counts[j] == 0)
                {
                    found = j;
                    break;
                }
            }

            if (found != -1)
            {
                return found;
            }
            else
            {
                return 0;
            }
        }

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

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

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

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

#if DEBUG
		static StreamReader getInput()
		{
			var resName = Assembly.GetCallingAssembly().GetManifestResourceNames()[0];
			var resource = Assembly.GetCallingAssembly().GetManifestResourceStream(resName);

			return new StreamReader(resource);
		}
#endif
    }
}


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

namespace ProgrammingContest.Codeforces.Round55
{
    class C
    {
        public static void Main()
        {
            int k = int.Parse(Console.ReadLine());
            string s = Console.ReadLine();
            int n = s.Length;
            bool[] used = new bool[26];
            for (int i = 0; i < n; i++)
                if (s[i] != '?')
                    used[s[i] - 'a'] = true;
            char[] res = s.ToCharArray();

            for (int i = 0; i < n; i++)
                if (res[i] != '?' && res[n - 1 - i] == '?')
                    res[n - 1 - i] = res[i];

            for (int i = k - 1; i >= 0; i--)
                if (!used[i])
                    for (int j = n / 2; j >= 0; j--)
                        if (res[j] == '?' && res[n - j - 1] == '?')
                        {
                            res[j] = res[n - j - 1] = (char)(i + 'a');
                            used[i] = true;
                            break;
                        }

            for (int i = 0; i < n; i++)
                if (res[i] == '?' && res[n - 1 - i] == '?')
                    res[n - 1 - i] = res[i] = 'a';

            for(int i = 0; i < k; i++)
                if (!used[i])
                {
                    Console.WriteLine("IMPOSSIBLE");
                    return;
                }

            for (int i = 0; i < n; i++)
                if (res[i] != res[n - 1 - i])
                {
                    Console.WriteLine("IMPOSSIBLE");
                    return;
                }

            Console.WriteLine(new string(res));
        }
    }
}


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

static class Extensions {
	public static T MyLast<T>(this IList<T> list) { return list[list.Count - 1]; }
}

class App {
	static string Solve() {
		var k = int.Parse(Console.ReadLine());
		var s = Console.ReadLine().ToArray();
		var n = s.Length;
		for (var i = 0 ; i < n / 2 ; i++) if (s[n - 1 - i] != '?') {
			if (s[n - 1 - i] == s[i]) continue;
			if (s[i] != '?') return null;
			s[i] = s[n - 1 - i];
		}
		var requiredChars = Enumerable.Range(0, k).Select(i => (char) ('a' + i)).ToArray();

		var firstHalf = Enumerable.Range(0, (n + 1) / 2);
		var spots = firstHalf.Count(i => s[i] == '?');
		var currentChars = requiredChars.Count(s.Contains);
		var missingChars = requiredChars.Where(c => !s.Contains(c)).ToArray();
		if (missingChars.Count() > spots) return null;
		foreach (var q in Enumerable.Range(0, spots - missingChars.Count())) {
			var i = firstHalf.First(ix => s[ix] == '?');
			s[i] = 'a';
		}
		foreach (var c in missingChars) {
			var i = firstHalf.First(ix => s[ix] == '?');
			s[i] = c;
		}

		foreach (var i in firstHalf) s[n - 1 - i] = s[i];
		return new string(s);
	}

	static void Main() {
		Console.WriteLine(Solve() ?? "IMPOSSIBLE");
	}
}


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

namespace Contest_59
{
    class Program
    {
        static void A()
        {
            var s = Console.ReadLine();
            var a = new string[] { s.ToUpper(), s.ToLower() };
            int[] k = new int[2];

            for (int j = 0; j < 2; j++)
            {
                for (int i = 0; i < s.Length; i++)
                {
                    if (s[i] == a[j][i])
                        k[j]++;
                }
            }
            if (k[0] > k[1])
                Console.WriteLine(a[0]);
            else Console.WriteLine(a[1]);
        }

        static void B()
        {
            int n = int.Parse(Console.ReadLine());
            var t = Console.ReadLine().Split(' ');

            List<int> a = new List<int>();
            List<int> b = new List<int>();

            foreach (var s in t)
            {
                int k = int.Parse(s);
                if (k % 2 == 0)
                    b.Add(k);
                else a.Add(k);
            }
            int sum = 0;
            int min = 0;
            if (a.Count == 0)
            {
                Console.WriteLine(0);
                return;
            }
            if (a.Count % 2 == 0)
            {
                min = a.Min();
            }

            foreach (var s in a)
                sum += s;
            foreach (var s in b)
                sum += s;
            sum -= min;
            Console.WriteLine(sum);
        }

        static void C()
        {
            int n = int.Parse(Console.ReadLine());
            char[] s = Console.ReadLine().ToCharArray();
            Dictionary<char, int> d = new Dictionary<char, int>();
            for (int i = 0; i < n; i++)
                d.Add((char)('a' + i), 0);
            int l = s.Length;
            bool ok = true;
            int needChar = 0;
            for (int i = 0, j = l - 1; i < l / 2; i++, j--)
            {
                if ((s[i] == '?') && (s[j] != '?')) { s[i] = s[j]; d[s[i]]++; }
                else if ((s[i] != '?') && (s[j] == '?'))
                {
                    s[j] =
                        s[i]; d[s[i]]++;
                }
                else if (s[i] != s[j])
                {
                    ok = false;
                    break;
                }
                else if (s[i] == '?') needChar++;
                else d[s[i]]++;
            }
            if (l % 2 == 1)
            {
                if (s[l / 2] == '?')
                    needChar++;
                else
                    d[s[l / 2]]++;
            }
            int used = 0;
            List<char> unused = new List<char>();
            foreach (var e in d)
            {
                if ((e.Key < 'a' + n) && (e.Value > 0))
                    used++;
                else unused.Add(e.Key);
            }

            if (n - used > needChar)
                ok = false;
            if (ok)
            {
                for (int i = 0, j = l - 1; i <= l / 2; i++, j--)
                {
                    if (s[i] == '?')
                    {
                        if (needChar > unused.Count)
                        {
                            s[i] = 'a';
                            s[j] = 'a';
                        }
                        else
                        {
                            s[i] = unused[0];
                            s[j] = unused[0];
                            if (unused.Count > 1)
                                unused.RemoveAt(0);
                        }
                        needChar--;
                    }
                }

                for (int i = 0; i < s.Length; i++)
                    Console.Write(s[i]);
            }
            else
            {
                Console.Write("IMPOSSIBLE");
            }
            Console.WriteLine();
        }

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


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

namespace CodeForces
{
	internal class Template
	{
		private static readonly Scanner cin = new Scanner();

		private static void Main()
		{
			//Console.SetIn(new StreamReader(@"C:\CodeForces\input.txt"));
			new Template().Solve();
			Console.ReadLine();
		}

		private void Solve()
		{
			var n = cin.NextInt();
			var m = cin.NextInt();
			var k = cin.NextInt();
			var a = new int[n];
			for (var i = 0; i < a.Length; i++)
			{
				a[i] = cin.NextInt();
			}
			Array.Sort(a);
			Array.Reverse(a);
			for (var i = 0; i <= n; i++)
			{
				if (k >= m)
				{
					Console.WriteLine(i);
					return;
				}
				if (i == n)
				{
					Console.WriteLine(-1);
					return;
				}
				k += a[i] - 1;
			}
		}
	}

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

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

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

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

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


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

namespace ProjectEuler
{
    class timepass
    {

        static void Main(string[] args)
        {
            Stopwatch stopWatch = new Stopwatch();
            stopWatch.Start();
            String s = Console.ReadLine();
            string[] values = s.Split(' ');

            int n = int.Parse(values[0]);
            int m = int.Parse(values[1]);
            int k = int.Parse(values[2]);

            s = Console.ReadLine();
            values = s.Split(' ');
            int[] filter = new int[n];
            for (int i = 0; i < n; i++)
            {
                filter[i] = int.Parse(values[i]);

            }
            Array.Sort<int>(filter);
            Array.Reverse(filter);
            int count=0;
            while ((m > k) &&(count<n))
            {
                m = m - filter[count];
                m = m + 1;
                count++;
            }
            if((m!=k)&&(count==n))
                Console.WriteLine(-1);
            else
                Console.WriteLine(count);

              //Console.Read();
        }
    }
}


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

// (づ°ω°)づﾐ★゜・。。・゜゜・。。・゜☆゜・。。・゜゜・。。・゜
public class Solver
{
    private int[] dr = {1, 0, -1, 0};
    private int[] dc = {0, 1, 0, -1};

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

        int nt = 0, nb = 0;
        for (int i = 0; i < n; i++)
            for (int j = 0; j < m; j++)
                if (char.IsDigit(a[i][j]))
                    nt = Math.Max(nt, a[i][j] - '0');
                else if (a[i][j] == 'B')
                    nb++;
        if (nt == 0)
        {
            Write(0);
            return;
        }
        var price = ReadAndTransposeIntMatrix(nt)[0];

        var pos = new int[nt + nb][];
        nb = 0;
        int sr = 0, sc = 0;
        for (int i = 0; i < n; i++)
            for (int j = 0; j < m; j++)
                if (char.IsDigit(a[i][j]))
                    pos[a[i][j] - '1'] = new[] { i, j };
                else if (a[i][j] == 'B')
                    pos[nt + nb++] = new[] { i, j };
                else if (a[i][j] == 'S')
                {
                    sr = i;
                    sc = j;
                }

        var f = new bool[n,m,1 << nt + nb];
        f[sr, sc, 0] = true;
        var q = new Queue<Tuple<int, int, int>>();
        q.Enqueue(Tuple.Create(sr, sc, 0));
        int ans = 0;
        int step = 0;
        int badSubMask = ((1 << nb) - 1) << nt;
        while (q.Count > 0)
        {
            var nq = new Queue<Tuple<int, int, int>>();
            while (q.Count > 0)
            {
                int r = q.Peek().Item1;
                int c = q.Peek().Item2;
                int mask = q.Dequeue().Item3;

                if (r == sr && c == sc && (mask & badSubMask) == 0)
                {
                    int s = 0;
                    for (int i = 0; i < nt; i++)
                        if ((mask >> i & 1) == 1)
                            s += price[i];
                    ans = Math.Max(ans, s - step);
                }

                for (int i = 0; i < 4; i++)
                {
                    int nr = r + dr[i];
                    int nc = c + dc[i];
                    if (nr < 0 || nr == n || nc < 0 || nc == m || a[nr][nc] != '.' && a[nr][nc] != 'S')
                        continue;
                    int nmask = mask;
                    if (i == 0)
                    {
                        for (int j = 0; j < nt + nb; j++)
                            if (nr == pos[j][0] && nc < pos[j][1])
                                nmask ^= 1 << j;
                    }
                    else if (i == 2)
                    {
                        for (int j = 0; j < nt + nb; j++)
                            if (nr == pos[j][0] - 1 && nc < pos[j][1])
                                nmask ^= 1 << j;
                    }
                    if (!f[nr, nc, nmask])
                    {
                        f[nr, nc, nmask] = true;
                        nq.Enqueue(Tuple.Create(nr, nc, nmask));
                    }
                }
            }
            q = nq;
            step++;
        }

        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("hull.in");
        //writer = new StreamWriter("hull.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
}


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

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

        private static void Main(string[] args)
        {
            int h1 = Next(), h2 = Next(), a = Next(), b = Next();

            int delta = h2 - 8*a - h1;
            if (delta <= 0)
                writer.WriteLine("0");
            else
            {
                if (a <= b)
                    writer.WriteLine("-1");
                else
                {
                    writer.WriteLine(1 + (delta-1)/(12*(a - b)));
                }
            }

            writer.Flush();
        }

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


using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using static System.Math;

public static class P
{
    public static void Main()
    {
        var h = Console.ReadLine().Split().Select(long.Parse).ToArray();
        var h1 = h[0];
        var h2 = h[1];
        var ab = Console.ReadLine().Split().Select(long.Parse).ToArray();
        h1 += ab[0] * 8;
        if (h2 <= h1)
        {
            Console.WriteLine(0);
            return;
        }
        if (ab[0] <= ab[1])
        {
            Console.WriteLine(-1);
            return;
        }
        int day = 1;
        while (true)
        {
            h1 -= ab[1] * 12;
            h1 += ab[0] * 12;
            if (h2 <= h1)
            {
                Console.WriteLine(day);
                return;
            }
            day++;
        }
    }
}


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

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

namespace ed32d
{
    class Program
    {
        static string _inputFilename = "input.txt";
        static string _outputFilename = "output.txt";
        static bool _useFileInput = false;

        static void Main(string[] args)
        {
            StreamWriter file = null;
#if DEBUG
			Console.SetIn(getInput());
#else
            if (_useFileInput)
            {
                Console.SetIn(File.OpenText(_inputFilename));
                file = new StreamWriter(_outputFilename);
                Console.SetOut(file);
            }
#endif

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

        static void solution()
        {
            //var d1 = new Dictionary<string, int>();
            //for (int i = 0; i < 4; i++)
            //{
            //    for (int j = 0; j < 4; j++)
            //    {
            //        for (int m = 0; m < 4; m++)
            //        {
            //            for (int h = 0; h < 4; h++)
            //            {
            //                var val = string.Format("{0}{1}{2}{3}", i + 1, j + 1, m + 1, h + 1);
            //                if (i != 0 && j != 1 && m != 2 && h != 3 && !d1.ContainsKey(val))
            //                {
            //                    if (i != j && i != m && i != h && j != m && j != h && m != h)
            //                    {
            //                        d1[val] = 1;
            //                    }

            //                }
            //            }
            //        }
            //    }
            //}

            #region SOLUTION
            var d = readLongArray();
            var n = d[0];
            var k = d[1];

            var total = 1L;
            if (k == 1)
            {
                Console.WriteLine(total);
                return;
            }

            total += (n * (n - 1) / 2);
            if (k == 2)
            {
                Console.WriteLine(total);
                return;
            }

            var c = (n * (n - 1) * (n - 2) / (2L * 3));
            total += (c * 2);
            if (k == 3)
            {
                Console.WriteLine(total);
                return;
            }

            var c2 = (n * (n - 1) * (n - 2) * (n - 3) / (2L * 3 * 4));
            total += (c2 * 9);

            if (k == 4)
            {
                Console.WriteLine(total);
                return;
            }

            //var n = readInt();
            //var m = readInt();

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

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

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

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

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

#if DEBUG
		static StreamReader getInput()
		{
			var resName = Assembly.GetCallingAssembly().GetManifestResourceNames()[0];
			var resource = Assembly.GetCallingAssembly().GetManifestResourceStream(resName);

			return new StreamReader(resource);
		}
#endif
    }
}


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

public class Program
{
    int N, K;
    public void Solve()
    {
        checked
        {
            var sc = new Scanner();
            N = sc.NextInt();
            K = sc.NextInt();

            /*
             * n順列p
             *
             * n-k個以上 p_i = i
             *
             *
             */

            long ans = 0;
            for (int i = 0; i <= K; i++)
            {
                // i個選ぶ
                // i個並べる
                // !i

                ans += C(N, i) * A(i);
            }
            ans++;

            Console.WriteLine(ans);
        }
    }

    long C(int n, int m)
    {
        long r = 1;
        for (int i = 0; i < m; i++)
        {
            r *= n - i;
        }

        for (int i = 1; i <= m; i++)
        {
            r /= i;
        }
        return r;
    }

    long A(int n)
    {
        if (n <= 1) return 0;
        if (n == 2) return 1;
        else return (n - 1) * (A(n - 1) + A(n - 2));
    }

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

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

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

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

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

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

            return _line[_index++];
        }

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

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

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

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


using System;

class Program
{
        const int nMax = 53; // NOTE: Levels greater that 53 will be definately greater that any k.
        static string f0 = "What are you doing at the end of the world? Are you busy? Will you save us?";
        static string pa1 = "What are you doing while sending \"";
        static string pa2 = "\"? Are you busy? Will you send \"";
        static string pa3 = "\"?";
        static long[] fnLen = new long[nMax + 1];

        static void Main(string[] args)
        {
                fnLen[0] = f0.Length;
                for (var i = 1; i <= nMax; ++i)
                {
                        fnLen[i] = 2 * fnLen[i - 1] + pa1.Length + pa2.Length + pa3.Length;
                }

                var q = int.Parse(Console.ReadLine());
                var answer = new char[q];
                for (var i = 0; i < q; ++i)
                {
                        string[] input = Console.ReadLine().Split(' ');
                        int n = int.Parse(input[0]);
                        long k = long.Parse(input[1]) - 1;

                        answer[i] = Scan(n, k) ?? '.';

                }
                Console.WriteLine(string.Join(string.Empty, answer));
        }

        static char? Scan(int n, long k)
        {
                if (n == 0 && f0.Length <= k)
                        return null;

                if (n > 0 && n < nMax && (pa1.Length + fnLen[n - 1] + pa2.Length + fnLen[n - 1] + pa3.Length) <= k)
                        return null;

                for (var l = n; l > 0; --l)
                {
                        if (pa1.Length > k)
                        {
                                return pa1[(int)k];
                        }
                        k -= pa1.Length;
                        if (l - 1 > nMax || fnLen[l - 1] > k)
                        {
                                continue;
                        }
                        k -= fnLen[l - 1];
                        if (pa2.Length > k)
                        {
                                return pa2[(int)k];
                        }
                        k -= pa2.Length;
                        if (l - 1 > nMax || fnLen[l - 1] > k)
                        {
                                continue;
                        }
                        k -= fnLen[l - 1];
                        if (pa3.Length > k)
                        {
                                return pa3[(int)k];
                        }
                }

                return f0[(int)k];
        }
}


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 Inf = (long) 2e18;
		long[][] L = new long[100001][];
		for(int i=0;i<=100000;i++){
			L[i] = new long[5];
		}

		long f = F.Length;
		long s = S.Length;
		long t = T.Length;
		long u = U.Length;
		for(int i=1;i<5;i++)L[0][i] = f;
		for(int i=1;i<=100000;i++){
			long tot = 0;
			L[i][0] = s;
			tot += s;
			L[i][1] = Math.Min(Inf,L[i][0] + L[i-1][4]);
			L[i][2] = Math.Min(Inf,L[i][1] + t);
			L[i][3] = Math.Min(Inf,L[i][2] + L[i-1][4]);
			L[i][4] = Math.Min(Inf,L[i][3] + u);
		}

		for(int q = 0;q<Q;q++){
			int n = N[q];
			long k = K[q];
			for(int i=n; i>=0; i--){
//Console.WriteLine(String.Join(" ",L[i]));
				if(0 <= k & k < L[i][0]){
					Console.Write(S[(int)k]);
					break;
				}
				if(L[i][0] <= k && k < L[i][1]){
					if(i == 0){
						Console.Write(F[(int)k]);
						break;
					}
					k -= L[i][0];
					continue;
				}
				if(L[i][1] <= k && k < L[i][2]){
					Console.Write(T[(int)(k - L[i][1])]);
					break;
				}
				if(L[i][2] <= k && k < L[i][3]){
					k -= L[i][2];
					continue;
				}
				if(L[i][3] <= k && k < L[i][4]){
					Console.Write( U[(int)(k - L[i][3])]);
					break;
				}
				Console.Write('.');break;
			}
		}

	}
	String F = "What are you doing at the end of the world? Are you busy? Will you save us?";
	String S = "What are you doing while sending \"";
	String T = "\"? Are you busy? Will you send \"";
	String U = "\"?";

	int Q;
	int[] N;
	long[] K;
	public Sol(){
		Q = ri();
		N = new int[Q];
		K = new long[Q];
		for(int i=0;i<Q;i++){
			var d = rla();
			N[i] = (int) d[0]; K[i] = d[1] - 1;
		}
	}

	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));}
}


/*
csc -debug C.cs && mono --debug C.exe <<< "10 2"
*/

using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Reflection;
// using System.Numerics;

public class HelloWorld {
    public static void SolveCodeForces() {
        var x = cin.NUL();
        var n = cin.NUL();

// var sieve = GetPrimeSieve(13);
// var primes = new List<int>();
// for (var p = 2; p < sieve.Length; p++) if (!sieve[p]) primes.Add(p);
// System.Console.WriteLine("Sieve: " + primes.Join());
        // var sieve = GetPrimeSieve(100);
        var sieve = GetPrimeSieve(100000);

        var primeDivs = new HashSet<ulong>();
        for (var p = 1ul; p * p <= x; p++)
            if (x % p == 0) {
                if (p > 1 && !sieve[p]) primeDivs.Add(p);
                var q = x / p;
                if (q > 1 && q != p && (int)q < sieve.Length && !sieve[q]) primeDivs.Add(q);
                if (q > 1 && q != p && (int)q >= sieve.Length && IsPrime(q)) primeDivs.Add(q);
            }
        if (primeDivs.Count == 0)
            primeDivs.Add(x);

// System.Console.WriteLine(primeDivs.Join());

        var ans = 1ul;

        // BigInteger nn = n;

        foreach (var p in primeDivs) {
            var pow = 0ul;

            // var ppow = p;
            // while (ppow <= n) {
            //     pow += n / ppow;
            //     ppow *= p;
            // }

            // BigInteger ppow = p;
            // while (ppow <= nn) {
            //     pow += n / (ulong)ppow;
            //     ppow *= p;
            // }

            var ppow = 1ul;
            while (ppow <= n / p) {
                ppow *= p;
                pow += n / ppow;
            }

            var curr = ModPow(p, pow, MOD);

            ans = ans * curr % MOD;
        }

        System.Console.WriteLine(ans);
    }

    const ulong MOD = 1000000007ul;

    public static ulong ModPow(ulong x, ulong exp, ulong mod) {
        ulong ret = 1ul;
        while (exp > 0) {
            if (exp % 2 == 1) ret = ret * x % mod;
            x = x * x % mod;
            exp /= 2;
        }
        return ret;
    }

    static bool[] GetPrimeSieve(int max) {
        var sieve = new bool[max + 1];
        for (var a = 2; 2 * a <= max; a++) {
            if (!sieve[a]) {
                for (var b = 2 * a; b <= max; b += a)
                    sieve[b] = true;
            }
        }
        return sieve;
    }

    public static bool IsPrime(ulong n) {
        if (n == 2) return true;

        if (n < 2 || n % 2 == 0)
            return false;

        var d = n - 1;
        var s = 0ul;
        while (d % 2 == 0) {
            d /= 2;
            s += 1;
        }

        var arr =
            n < 4759123141ul ? new ulong[] {2, 7, 61}
            : n < 341550071728321ul ? new ulong[] {2, 3, 5, 7, 11, 13, 17}
            : new ulong[] {2, 3, 5, 7, 11, 13, 17, 19, 23};

        foreach (var a in arr)
        {
            if (a >= n) return true;

            var x = ModPow(a, d, n);

            if (x == 1) continue;
            if (x == n - 1) continue;

            for (var r = 1ul; r < s; r++) {
                x = ModPow(x, 2, n);
                if (x == 1) return false;
                if (x == n - 1) break;
            }

            if (x != n - 1) return false;
        }
        return true;
    }

    // static bool IsPrime(ulong n) {
    //     if (n <= (1ul << 14)) {
    //         int x = (int) n;
    //         if (x <= 4 || x % 2 == 0 || x % 3 == 0)
    //             return x == 2 || x == 3;
    //         for (int i = 5; i * i <= x; i += 6)
    //             if (x % i == 0 || x % (i + 2) == 0)
    //                 return false;
    //         return true;
    //     }

    //     ulong s = n - 1;
    //     int t = 0;
    //     while (s % 2 == 0) { s /= 2; ++t; }

    //     foreach (var aa in new[] {2ul, 325ul, 9375ul, 28178ul, 450775ul, 9780504ul, 1795265022ul}) {
    //         var a = aa;
    //         if (!(a %= n))
    //             return true;
    //         ulong f = ModPow(a, s, n);
    //         if (f == 1 || f == n - 1) continue;
    //         for (int i = 1; i < t; ++i)
    //             if ((f = mulmod(f, f, n)) == n - 1)
    //                 goto nextp;
    //         return false;
    //         nextp: ;
    //     }
    //     return true;
    // }

    static Scanner cin = new Scanner();
    static StringBuilder cout = new StringBuilder();

    static public void Main () {
        SolveCodeForces();
        // IncreaseStack(SolveCodeForces);
        // System.Console.Write(cout.ToString());
    }

    public static void IncreaseStack(ThreadStart action, int stackSize = 128000000)
    {
        var thread = new Thread(action, stackSize);
        thread.Start();
        thread.Join();
    }
}

public static class Helpers {
    public static string Join<T>(this IEnumerable<T> arr, string sep = " ") {
        return string.Join(sep, arr);
    }

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

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

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

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

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

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

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

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

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

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

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


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

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

public class HelloWorld {
    public static void SolveCodeForces() {
        var x = cin.NUL();
        var n = cin.NUL();

        var divs = new List<ulong>();
        for (var p = 2ul; p * p <= x; p++) {
            if (x % p == 0) {
                divs.Add(p);
                while (x % p == 0) x /= p;
            }
        }
        if (x > 1)
            divs.Add(x);

// System.Console.WriteLine(divs.Join());

        var ans = 1ul;

        foreach (var p in divs) {
            var pow = 0ul;

            var ppow = 1ul;
            while (ppow <= n / p) {
                ppow *= p;
                pow += n / ppow;
            }

            ans = ans * ModPow(p, pow, MOD) % MOD;
        }

        System.Console.WriteLine(ans);
    }

    const ulong MOD = 1000000007ul;

    public static ulong ModPow(ulong x, ulong exp, ulong mod) {
        ulong ret = 1ul;
        while (exp > 0) {
            if (exp % 2 == 1) ret = ret * x % mod;
            x = x * x % mod;
            exp /= 2;
        }
        return ret;
    }

    static Scanner cin = new Scanner();
    static StringBuilder cout = new StringBuilder();

    static public void Main () {
        SolveCodeForces();
        // IncreaseStack(SolveCodeForces);
        // System.Console.Write(cout.ToString());
    }

    public static void IncreaseStack(ThreadStart action, int stackSize = 128000000)
    {
        var thread = new Thread(action, stackSize);
        thread.Start();
        thread.Join();
    }
}

public static class Helpers {
    public static string Join<T>(this IEnumerable<T> arr, string sep = " ") {
        return string.Join(sep, arr);
    }

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

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

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

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

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

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

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

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

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

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

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


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

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(System.Console.ReadLine());
            int m = int.Parse(System.Console.ReadLine());
            int[] benches = new int[n];
            for(int i=0;i<n;i++)
            {
                benches[i] = int.Parse(System.Console.ReadLine());
            }
            int mx=0;
            int mn=0, bn = -1;
            for(int i=0;i<m;i++)
            {
                bn=-1;
                for(int j=0;j<n;j++)
                {
                    if(bn==-1 || benches[j] < mn)
                    {
                        bn = j;
                        mn = benches[j];
                    }
                    if(i==0 && benches[j]>mx)
                    {
                        mx = benches[j];
                    }
                }
                benches[bn]++;
            }
            bn=-1;
            for(int j=0;j<n;j++)
            {
                if(bn==-1 || benches[j] > mn)
                {
                    bn = j;
                    mn = benches[j];
                }
            }
            System.Console.WriteLine(String.Format("{0} {1}", mn, mx + m));
        }
    }
}


using System;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            int numBenches = Convert.ToInt32(Console.ReadLine());
            int numExtraPeople = Convert.ToInt32(Console.ReadLine());
            int modifiedNumExtraPeople = numExtraPeople;
            int[] benches = new int[numBenches];
            for (int i = 0; i < numBenches; i++) benches[i] = Convert.ToInt32(Console.ReadLine());
            int maxPeopleCount = FindMax(benches);
            foreach (var i in benches) modifiedNumExtraPeople -= maxPeopleCount - i;
            modifiedNumExtraPeople = Math.Max(0, modifiedNumExtraPeople);
            Console.WriteLine("{0} {1}", maxPeopleCount + Math.Ceiling((double)modifiedNumExtraPeople / numBenches), numExtraPeople + maxPeopleCount);
        }

        static int FindMax(int[] array)
        {
            int max = Int32.MinValue;
            foreach(var i in array)
            {
                if (i > max) max = i;
            }
            return max;
        }
    }
}


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

namespace CodeForces
{
    static class Reader
    {
        public static int NextInt()
        {
            int ret = 0;
            char c;

            while (!char.IsDigit(c = (char)Console.Read()))
            {
                if (c == '-')
                    return -NextInt();
            }
            do
            {
                ret = ret * 10 + c - '0';
            } while (char.IsDigit(c = (char)Console.Read()));

            return ret;
        }

        public static double NextDouble()
        {
            double ret = 0;
            char c;

            while (!char.IsDigit(c = (char)Console.Read()))
            {
                if (c == '-')
                    return -NextDouble();
            }
            do
            {
                ret = ret * 10 + c - '0';
            } while (char.IsDigit(c = (char)Console.Read()));
            if (c != '.') return ret;

            double p10 = 0.1;
            while (char.IsDigit(c = (char)Console.Read()))
            {
                ret += p10 * (c - '0');
                p10 *= 0.1;
            }

            return ret;
        }

        public static string NextToken()
        {
            StringBuilder ret = new StringBuilder();
            char c;

            while (char.IsWhiteSpace(c = (char)Console.Read())) ;
            do
            {
                ret.Append(c);
            } while (!char.IsWhiteSpace(c = (char)Console.Read()));

            return ret.ToString();
        }
    }

    class Program
    {
        static int GCD(int n, int m)
        {
            return m > 0 ? GCD(m, n % m) : n;
        }

        static void Main(string[] args)
        {
            int a, b, x, y;

            a = Reader.NextInt();
            b = Reader.NextInt();
            x = Reader.NextInt();
            y = Reader.NextInt();

            int g = GCD(x, y);
            int m = Math.Min(a / (x / g), b / (y / g));

            Console.WriteLine("{0} {1}", x / g * m, y / g * m);
        }
    }
}


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

// (づ°ω°)づﾐe★゜・。。・゜゜・。。・゜☆゜・。。・゜゜・。。・゜
public class Solver
{
    int Gcd(int a, int b)
    {
        return b > 0 ? Gcd(b, a % b) : a;
    }

    public void Solve()
    {
        int a = ReadInt();
        int b = ReadInt();
        int x = ReadInt();
        int y = ReadInt();

        int g = Gcd(x, y);
        x /= g;
        y /= g;

        if (a < x || b < y)
            Write(0, 0);
        else
        {
            int v = Math.Min(a / x, b / y);
            Write(x * v, y * v);
        }
    }

    #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("input.txt");
        //writer = new StreamWriter("output.txt");
#endif
        try
        {
            new Solver().Solve();
            //var thread = new Thread(new Solver().Solve, 1024 * 1024 * 128);
            //thread.Start();
            //thread.Join();
        }
        catch (Exception ex)
        {
            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
}


using System;
using System.Collections.Generic;

namespace Contest
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] nm = Console.ReadLine().Split();
            long n = int.Parse(nm[0]);
            long m = long.Parse(nm[1]);
            long[] fact = new long[250005];
            fact[0] = 1;
            for (int i = 1; i <= n; i++)
                fact[i] = fact[i - 1] * i % m;
            long ret = 0;
            for (int i = 1; i <= n; i++)
            {
                ret += (n - i + 1) * (fact[i] * fact[n - i + 1] % m);
                ret %= m;
            }
            Console.WriteLine(ret);
        }
    }
}


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

public static class P
{
    static int MOD;

    public static void Main()
    {
        var nm = Console.ReadLine().Split().Select(int.Parse).ToArray();
        var n = nm[0];
        MOD = nm[1];
        long res = 0;
        for (int frameSize = 1; frameSize <= n; frameSize++)
        {
            res += (n - frameSize + 1) * Factorial(frameSize) % MOD * Factorial(n - frameSize + 1) % MOD;
            res %= MOD;
        }
        Console.WriteLine(res);
    }

    static List<long> factorialMemo = new List<long>() { 1 };
    static long Factorial(int x)
    {
        for (int i = factorialMemo.Count; i <= x; i++) factorialMemo.Add(factorialMemo.Last() * i % MOD);
        return factorialMemo[x];
    }
}


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

class Myon
{
    public Myon() { }
    static void Main(string[] args)
    {
        new Myon().calc();
    }

    void calc()
    {
        string[] board = new string[3];
        for (int i = 0; i < 3; i++)
        {
            board[i] = Console.ReadLine();
        }
        if (calc2(board)) Console.WriteLine("YES");
        else Console.WriteLine("NO");
    }

    bool calc2(string[] board)
    {
        for (int i = 0; i < 3; i++)
        {
            for (int j = 0; j < 3; j++)
            {
                if (board[i][j] != board[2 - i][2 - j]) return false;
            }
        }
        return true;
    }
}


using System;
static class P {
    static void Main() {
        string s = "", r = "YES"; int i = 0;
        for (; i < 3; ++i) { s += Console.ReadLine(); }
        i = 0; int j = s.Length - 1;
        while (i < j) { if (s[i++] != s[j--]) { r = "NO"; break; } }
        Console.WriteLine(r);
    }
}


using System;
using System.Diagnostics;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using Enu = System.Linq.Enumerable;

class Solution {
    void calc() {
        long p, q;
        rlo(out p, out q);
        int n = 5000000;
        var primes = sieveOfEratosthenes(n);
        //Console.WriteLine(primes.Count);
        //Console.WriteLine(Enu.Range(1, n).Count(e => isPalindorome(e)));
        int idx = 0;
        long pi = 0, rub = 0;
        int ans = 0, last = primes.Last();
        for(int i = 1; i <= last; i++) {
            if(primes[idx] == i) {
                pi++;
                idx++;
            }
            if(isPalindorome(i)) rub++;
            if(q * pi <= p * rub) {
                ans = i;
            }
        }
        if(ans > 0) Console.WriteLine(ans);
        else Console.WriteLine("Palindromic tree is better than splay tree");
    }
    bool isPalindorome(int n) {
        string s = n.ToString();
        for(int i = 0; i < s.Length; i++) {
            if(s[i] != s[s.Length - 1 - i]) return false;
        }
        return true;
    }
    public static List<int> sieveOfEratosthenes(int n) {
        List<int> primes = new List<int>();
        bool[] isPrime = Enumerable.Repeat(true, n + 1).ToArray();
        isPrime[0] = isPrime[1] = false;
        for(int i = 2; i <= n; i++) {
            if(isPrime[i]) {
                primes.Add(i);
                for(int j = 2 * i; j <= n; j += i) isPrime[j] = false;
            }
        }
        return primes;
    }

    static void Main(string[] args) {
        new Solution().calc();
    }

    #region
    static int ri() { return int.Parse(Console.ReadLine()); }
    static int[] ria(int n) {
        if(n <= 0) { Console.ReadLine(); return new int[0]; }
        else return Console.ReadLine().Trim().Split(' ').Select(int.Parse).ToArray();
    }
    static void rio(out int p1) { p1 = ri(); }
    static void rio(out int p1, out int p2) { var r = ria(2); p1 = r[0]; p2 = r[1]; }
    static void rio(out int p1, out int p2, out int p3) { var r = ria(3); p1 = r[0]; p2 = r[1]; p3 = r[2]; }
    static void rio(out int p1, out int p2, out int p3, out int p4) { var r = ria(4); p1 = r[0]; p2 = r[1]; p3 = r[2]; p4 = r[3]; }
    static void rio(out int p1, out int p2, out int p3, out int p4, out int p5) { var r = ria(5); p1 = r[0]; p2 = r[1]; p3 = r[2]; p4 = r[3]; p5 = r[4]; }
    static long rl() { return long.Parse(Console.ReadLine()); }
    static long[] rla(int n) {
        if(n <= 0) { Console.ReadLine(); return new long[0]; }
        else return Console.ReadLine().Trim().Split(' ').Select(long.Parse).ToArray();
    }
    static void rlo(out long p1) { p1 = rl(); }
    static void rlo(out long p1, out long p2) { var r = rla(2); p1 = r[0]; p2 = r[1]; }
    static void rlo(out long p1, out long p2, out long p3) { var r = rla(3); p1 = r[0]; p2 = r[1]; p3 = r[2]; }
    static void rlo(out long p1, out long p2, out long p3, out long p4) { var r = rla(4); p1 = r[0]; p2 = r[1]; p3 = r[2]; p4 = r[3]; }
    static void rlo(out long p1, out long p2, out long p3, out long p4, out long p5) { var r = rla(5); p1 = r[0]; p2 = r[1]; p3 = r[2]; p4 = r[3]; p5 = r[4]; }
    static double rd() { return double.Parse(Console.ReadLine()); }
    static double[] rda(int n) {
        if(n <= 0) { Console.ReadLine(); return new double[0]; }
        else return Console.ReadLine().Trim().Split(' ').Select(double.Parse).ToArray();
    }
    static void rdo(out double p1) { p1 = rd(); }
    static void rdo(out double p1, out double p2) { var r = rda(2); p1 = r[0]; p2 = r[1]; }
    static void rdo(out double p1, out double p2, out double p3) { var r = rda(3); p1 = r[0]; p2 = r[1]; p3 = r[2]; }
    static void rdo(out double p1, out double p2, out double p3, out double p4) { var r = rda(4); p1 = r[0]; p2 = r[1]; p3 = r[2]; p4 = r[3]; }
    static void rdo(out double p1, out double p2, out double p3, out double p4, out double p5) { var r = rda(5); p1 = r[0]; p2 = r[1]; p3 = r[2]; p4 = r[3]; p5 = r[4]; }
    static void swap<T>(ref T x, ref T y) { T temp = x; x = y; y = temp; }
    static void wa1<T>(T[] a) { Debug.WriteLine(string.Join(" ", a)); }
    static void wa2<T>(T[][] a) {
        foreach(var row in a) {
            Debug.WriteLine(String.Join(" ", row));
        }
    }
    [DebuggerDisplay("{x} , {y}")]
    class point<T> {
        public T x, y;
        public point(T x, T y) {
            this.x = x; this.y = y;
        }
    }
    #endregion
}

static class Extention {
    public static T[][] ToJagArray<T>(this T[,] a) {
        int n = a.GetLength(0), m = a.GetLength(1);
        var ret = new T[n][];
        for(int i = 0; i < n; i++) {
            ret[i] = new T[m];
            for(int j = 0; j < m; j++) {
                ret[i][j] = a[i, j];
            }
        }
        return ret;
    }

    public static bool InRange<T>(this T[,] a, int i, int j) {
        int n = a.GetLength(0), m = a.GetLength(1);
        return 0 <= i && i < n && 0 <= j && j < m;
    }
}