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
{
    class _4032
    {
        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 : IComparable
        {
            public long X { get; set; }
            public long Y { get; set; }
            public int CompareTo(object obj)
            {
                if (this.Y > ((Node)obj).Y)
                {
                    return 1;
                }
                if (this.Y == ((Node)obj).Y)
                {
                    return 0;
                }
                return -1;
            }
        }

        static bool isBig(long n, long s)
        {
            long sum = 0;
            var st = n.ToString();
            for (var i=0;i< st.Length; i++)
            {
                sum += long.Parse(st[i].ToString());
            }
            return n - sum >= s;
        }
        static void Main(String[] args)
        {
            var data = Console.ReadLine().Split(':').ToList();
            var first = data[0];
            var second = data[1];
            int i = 0;
            while(first[1] != second[0] || first[0] != second[1])
            {
                if(second == "59")
                {
                    second = "00";
                    var sb = new StringBuilder();
                    var newFirst = int.Parse(first) + 1;
                    if(newFirst == 24)
                    {
                        newFirst = 0;
                    }
                    if (newFirst < 10)
                    {
                        sb.Append("0");
                    }
                    sb.Append(newFirst);
                    first = sb.ToString();
                } else
                {
                    var newSecond = int.Parse(second) + 1;
                    var sb = new StringBuilder();
                    if(newSecond < 10)
                    {
                        sb.Append("0");
                    }
                    sb.Append(newSecond);
                    second = sb.ToString();
                }
                i++;
            }

            Console.WriteLine(i);

        }

    }
}


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

    bool calc(int day, int[] K, List<int>[] L, int Sum)
    {
        int used = 0;
        int money = day;
        for (int i = day - 1; i >= 0; i--)
        {
            if (i < L.Length)
            {
                foreach (var v in L[i])
                {
                    int buy = Min(K[v], money);
                    money -= buy;
                    K[v] -= buy;
                    used += buy;
                }
            }
            money = Min(i, money);
        }

        int remain = Sum - used;

        return remain * 2 <= (day - used);

    }
    void solve()
    {
        int N = cin.nextint;
        int M = cin.nextint;
        var K = cin.scanint;

        var L = new List<int>[200000];
        for (int i = 0; i < L.Length; i++)
        {
            L[i] = new List<int>();
        }
        for (int i = 0; i < M; i++)
        {
            L[cin.nextint - 1].Add(cin.nextint - 1);
        }
        int Sum = K.Sum();

        int ng = 0;
        int ok = Sum * 2;
        while (ok - ng > 1)
        {
            int mid = (ok + ng) / 2;

            var Z = new int[N];
            for (int i = 0; i < Z.Length; i++)
            {
                Z[i] = K[i];
            }

            if (calc(mid, Z, L, Sum))
            {
                ok = mid;
            }
            else
            {
                ng = mid;
            }
        }

        WriteLine(ok);

    }

}

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.Linq;
using CompLib.Util;

public class Program
{
    int N, M;
    int[] K;
    int[] D, T;
    int[] index;
    public void Solve()
    {
        var sc = new Scanner();
        N = sc.NextInt();
        M = sc.NextInt();
        K = sc.IntArray();
        D = new int[M];
        T = new int[M];
        for (int i = 0; i < M; i++)
        {
            D[i] = sc.NextInt();
            T[i] = sc.NextInt() - 1;
        }
        index = new int[M];
        for (int i = 0; i < M; i++)
        {
            index[i] = i;
        }

        Array.Sort(index, (l, r) => D[l].CompareTo(D[r]));

        // n種類ある
        // 毎日1獲得
        // 通常2 セール中は1支払えば買える
        // 種類iを丁度k[i]個買う
        // 毎日0個以上注文できる
        // 種類t[j]はd[j]日にセール

        //
        int ng = -1;
        int ok = 400000;
        while (ok - ng > 1)
        {
            int mid = (ok + ng) / 2;
            if (C(mid)) ok = mid;
            else ng = mid;
        }

        Console.WriteLine(ok);
    }

    // day日に達成できるか?
    bool C(int day)
    {
        // 区間内セール
        // 種類ごと一番最後
        // 前から

        int[] s = new int[N];
        for (int i = 0; i < N; i++)
        {
            s[i] = int.MaxValue;
        }

        for (int i = 0; i < M; i++)
        {
            if (D[index[i]] <= day)
            {
                s[T[index[i]]] = D[index[i]];
            }
        }

        var tmp = new int[N];
        for (int i = 0; i < N; i++)
        {
            tmp[i] = i;
        }
        Array.Sort(tmp, (l, r) => s[l].CompareTo(s[r]));
        //if (day == 8)
        //{
        //    Console.WriteLine("-----");
        //    Console.WriteLine(day);
        //    Console.WriteLine(string.Join(" ", s));
        //    Console.WriteLine(string.Join(" ", tmp));
        //}
        int nokori = 0;
        int m = 0;
        int p = 0;
        for (int i = 0; i < N; i++)
        {
            if (s[tmp[i]] == int.MaxValue)
            {
                nokori += K[tmp[i]];
            }
            else
            {
                // 買える分
                // s[i] - m

                int tt = Math.Min(K[tmp[i]], s[tmp[i]] - m);
                p += tt;
                m += tt;
                nokori += K[tmp[i]] - tt;
                //if (day == 8)
                //{
                //    Console.WriteLine($"{tmp[i]} {tt} {m}");
                //}
            }
        }
        //if(day == 8)
        //{
        //    Console.WriteLine("aaaa" + m);
        //}
        return nokori * 2 <= day - m;
    }

    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;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            long n = Convert.ToInt64(Console.ReadLine());long k = n / 2;
            if (n % 2 == 0)
            {

                if (k % 2 == 0)
                {
                    Console.WriteLine("0");
                }
                else
                {
                    Console.WriteLine("1");
                }
            }
            else
            {
                if (k % 2 == 0)
                {
                    Console.WriteLine("1");
                }
                else
                {
                    Console.WriteLine("0");
                }
            }
        }
    }
}


using System;

namespace CSharp
{
    class _1102A
    {
        public static void Main()
        {
            long n = long.Parse(Console.ReadLine());
            Console.WriteLine(((n * (n + 1)) / 2) % 2);
        }
    }
}


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

class Program
{
    static void Main(string[] args)
    {
        int size = Convert.ToInt32(Console.ReadLine());
        if (size == 0){Console.WriteLine(1);return;}
        int modulo = 1;
        for (int index = 0; index < size - 1; index++)
        {
            modulo *= 3;
            if (modulo > 1000003)
            {
                modulo %= 1000003;
            }
        }
        Console.WriteLine(modulo);
    }

}


using System;

class P {
  static void Main() {
    var n = int.Parse(Console.ReadLine()) - 1;
    var res = 1;
    while (n --> 0) res = (res * 3) % 1000003;
    Console.Write(res);
  }
}


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

namespace Op
{
    class Program
    {
        public static int Main(string[] args)
        {
            string[] line = Console.ReadLine().Split();
            long a,b,c,t;
            a=long.Parse(line[0]);
            b=long.Parse(line[1]);
            c=long.Parse(line[2]);
            for (long i=0;i<=Math.Min(a,b);i++)
                if (c==a-i+b-i) {Console.WriteLine("{0} {1} {2}", i,b-i,a-i);return 0;}
            Console.WriteLine("Impossible");
            //Console.ReadKey();
            return 0;
        }

    }
    }


using System;
using System.Collections.Generic;

namespace ConsoleApplication234
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] ok = new string[3]; int a, b, c;
            string read = Console.ReadLine();
            ok = read.Split(' ');
            a = int.Parse(ok[0]);
            b = int.Parse(ok[1]);
            c = int.Parse(ok[2]);

            int s = a + b + c;
            if (s%2==1)
            {
                Console.WriteLine("Impossible");
                return;
            }
            s /= 2;
            a = s - a; b = s - b; c = s - c;
            if (a < 0 || b < 0 || c < 0) Console.WriteLine("Impossible");
            else Console.WriteLine(c + " " + a + " " + b);
            //Console.ReadKey();
        }
    }
}


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

namespace test
{
	class MainClass
	{
		public static void Main (string[] args)
		{
			var n = Int32.Parse (Console.ReadLine ());

			var tList = Console.ReadLine ().Split (' ').Select (x => Int32.Parse (x)).OrderBy(x => x).ToList();

			var T = Int32.Parse (Console.ReadLine ());

			var maxLen = 1;
			var currentLen = 1;

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

				for (var j = i + 1; j < n; j++) {
					if (tList [j] - tList [i] > T) {
						break;
					}

					currentLen++;
				}

				if (currentLen > maxLen) {
					maxLen = currentLen;
				}
			}

			Console.WriteLine (maxLen);

		}
	}
}


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

namespace codeforces386
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = Convert.ToInt32(Console.ReadLine());
            string[] inx = Console.ReadLine().Split(' ');
            int[] data = new int[n];
            for (int i = 0; i < n; i++)
            {
                data[i] = Convert.ToInt32(inx[i]);
            }
            int t = Convert.ToInt32(Console.ReadLine());
            if (n == 1)
            {
                Console.WriteLine(1);
                return;
            }
            Array.Sort(data);
            int a, b, max, curr;
            a = 0; b = 0;
            max = 0;
            curr = 0;
            while (b < n)
            {
                while (b < n && Math.Abs(data[a] - data[b]) <= t)
                {
                    b++;
                    curr++;
                    if (curr > max) max = curr;
                }
                if (b == n) break;
                while (Math.Abs(data[a] - data[b]) > t)
                {
                    a++;
                    curr--;
                }
            }
            Console.WriteLine(max);
        }
    }
}


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

namespace ConsoleApp15
{
    class Program
    {

        static bool ok(int k, int n, int[] a)
        {
            int cant = 0;
            int m = a.Length;
            for (int i = 0; i < m; i++)
                cant += a[i] / k;
            return cant >= n;
        }

        static void Main(string[] args)
        {
            string[] line = Console.ReadLine().Split(' ');
            int n = int.Parse(line[0]);
            int m = int.Parse(line[1]);
            line = Console.ReadLine().Split(' ');
            int[] a = new int[m];
            for (int i = 0; i < m; i++)
                a[i] = int.Parse(line[i]);
            int[] b = new int[105];
            for (int i = 0; i < m; i++)
                b[a[i]]++;

            int ans = 0;
            int lo = 1;
            int hi = m;
            while(lo <= hi)
            {
                int mid = (lo + hi) >> 1;
                if(ok(mid, n, b))
                {
                    ans = mid;
                    lo = mid + 1;
                }
                else
                {
                    hi = mid - 1;
                }
            }

            Console.WriteLine(ans);

        }
    }
}


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)
        {
            string no1 = Console.ReadLine();
            List<string> ar1 = no1.Split(' ').ToList();
            List<int> ar = ar1.Select(s => int.Parse(s)).ToList();
            no1 = Console.ReadLine();
            List<string> ar2 = no1.Split(' ').ToList();
            List<int> ar3 = ar2.Select(s => int.Parse(s)).ToList();
            Console.WriteLine(PlainningTheExpedition(ar.ElementAt(0), ar.ElementAt(1), ar3));
          //  Console.ReadKey();

        }
        public static int PlainningTheExpedition(int Participants, int typesOfFood, List<int> foods)
        {
            if (Participants == 0)
            {
                return 0;
            }
            List<int> distinctTypes = foods.Distinct().ToList();
            List<int> noOfPackages = new List<int>();
            distinctTypes.ForEach(x => noOfPackages.Add(foods.Count(y => y == x)));
            noOfPackages.Sort();
            int sum = noOfPackages.Sum();
            int maxdays = sum / Participants;
            if (maxdays == 0){
                return 0;
            }
            for (int i = maxdays; i > 0 ; i--)
            {
                int pos = 0;
                for (int j = 0; j < noOfPackages.Count; j++)
                {
                    pos += noOfPackages[j] / i;
                }
                if (pos >= Participants) {
                    return i;
                }
            }
            return 0;
        }

    }
}
//Planning The expedition
//participants - n , type - h
//list = arrType.distinct;
//forech list (list1.push(arrType.Count(item)))
//index = list1.length-n

//7
// 100 100 9 7 6


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
{
    long Fun(int n, int m, int p, int[] a)
    {
        if (p == n)
        {
            var set = new HashSet<int>();
            for (int mask = 0; mask < 1 << n; mask++)
            {
                int x = 0;
                for (int i = 0; i < n; i++)
                    if ((mask >> i & 1) == 1)
                        x = x * 10 + a[i];
                set.Add(x);
            }
            return set.Count;
        }

        long ret = 0;
        for (int i = 1; i <= m; i++)
        {
            a[p] = i;
            ret += Fun(n, m, p + 1, a);
        }
        return ret;
    }

    const int MOD = 1000000007;

    long Fun2(int n, int m)
    {
        int b = 2 * m - 1;
        long p = m;
        long ret = 2 * m;
        for (int i = 1; i < n; i++)
        {
            ret = (ret * b + p) % MOD;
            p = p * m % MOD;
        }
        return ret;
    }

    public void Solve()
    {
        int n = ReadInt();
        int m = ReadInt();
        Write(Fun2(n, m));
    }

    #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
        {
            //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.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 nm = Console.ReadLine().Split().Select(int.Parse).ToArray();
        var n = nm[0]; //num
        var m = nm[1]; //kind

        //Console.WriteLine(Stupid(1, 1));
        //Console.WriteLine(Stupid(2, 2));
        //Console.WriteLine(Stupid(3, 3));
        //Console.WriteLine(Stupid(4, 6));
        //Console.WriteLine(Stupid(5, 5));
        //Console.WriteLine(Stupid(6, 3));

        //1/mの確率で次の状態に進めるオートマトンが、nターンでi回以上先の状態まで進む通り数

        ModInt comb = Power(m, n);
        ModInt res = comb;
        for (int len = 1; len <= n; len++)
        {
            //len回進めなかった場合
            //つまり、len-1回あたりが出て、n-len+1回はずれ
            comb -= Power(m - 1, n - len + 1) * Factorial(n) / Factorial(len - 1) / Factorial(n - len + 1);
            res += comb * Power(m, len);
        }
        Console.WriteLine(res);
    }

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

    static ModInt Power(ModInt n, long m)
    {
        ModInt pow = n;
        ModInt res = 1;
        while (m > 0)
        {
            if ((m & 1) == 1) res *= pow;
            pow *= pow;
            m >>= 1;
        }
        return res;
    }

    static ModInt Stupid(int n, int m)
    {
        List<string> seq = new List<string>() { "" };
        for (int i = 0; i < n; i++)
        {
            var newseq = new List<string>();
            foreach (var item in seq)
            {
                for (int j = 1; j <= m; j++)
                {
                    newseq.Add(item + (char)('0' + j));
                }
            }
            seq = newseq;
        }
        int res = 0;
        Dictionary<string, int> freqs = new Dictionary<string, int>();
        foreach (var item in seq)
        {
            HashSet<string> set = new HashSet<string>() { "" };
            for (int i = 0; i < (1 << item.Length); i++)
            {
                string s = "";
                for (int j = 0; j < item.Length; j++)
                {
                    if ((i >> j & 1) == 1) s += item[j];
                }
                set.Add(s);
            }
            //for (int i = 0; i < item.Length; i++)
            //    for (int j = i + 1; j <= item.Length; j++)
            //        set.Add(item[i..j]);
            foreach (var s in set)
            {
                if (!freqs.ContainsKey(s)) freqs[s] = 0;
                freqs[s]++;
            }
            res += set.Count;
        }
        foreach (var group in freqs.GroupBy(x => x.Value).OrderBy(x => x.Key))
        {
            Console.WriteLine($"{group.Key} {group.Count()} {string.Join(" ", group.Take(30).Select(x => x.Key))}");
        }
        return res;
    }
}

struct ModInt
{
    public const int Mod = 1000000007;
    const long POSITIVIZER = ((long)Mod) << 31;
    long Data;
    public ModInt(long data) { if ((Data = data % Mod) < 0) Data += Mod; }
    public static implicit operator long(ModInt modInt) => modInt.Data;
    public static implicit operator ModInt(long val) => new ModInt(val);
    public static ModInt operator +(ModInt a, int b) => new ModInt() { Data = (a.Data + b + POSITIVIZER) % Mod };
    public static ModInt operator +(ModInt a, long b) => new ModInt(a.Data + b);
    public static ModInt operator +(ModInt a, ModInt b) { long res = a.Data + b.Data; return new ModInt() { Data = res >= Mod ? res - Mod : res }; }
    public static ModInt operator -(ModInt a, int b) => new ModInt() { Data = (a.Data - b + POSITIVIZER) % Mod };
    public static ModInt operator -(ModInt a, long b) => new ModInt(a.Data - b);
    public static ModInt operator -(ModInt a, ModInt b) { long res = a.Data - b.Data; return new ModInt() { Data = res < 0 ? res + Mod : res }; }
    public static ModInt operator *(ModInt a, int b) => new ModInt(a.Data * b);
    public static ModInt operator *(ModInt a, long b) => a * new ModInt(b);
    public static ModInt operator *(ModInt a, ModInt b) => new ModInt() { Data = a.Data * b.Data % Mod };
    public static ModInt operator /(ModInt a, ModInt b) => new ModInt() { Data = a.Data * GetInverse(b) % Mod };
    public static bool operator ==(ModInt a, ModInt b) => a.Data == b.Data;
    public static bool operator !=(ModInt a, ModInt b) => a.Data != b.Data;
    public override string ToString() => Data.ToString();
    public override bool Equals(object obj) => (ModInt)obj == this;
    public override int GetHashCode() => (int)Data;
    static long GetInverse(long a)
    {
        long div, p = Mod, x1 = 1, y1 = 0, x2 = 0, y2 = 1;
        while (true)
        {
            if (p == 1) return x2 + Mod; div = a / p; x1 -= x2 * div; y1 -= y2 * div; a %= p;
            if (a == 1) return x1 + Mod; div = p / a; x2 -= x1 * div; y2 -= y1 * div; p %= a;
        }
    }
}


using System;

namespace equations
{
    class MainClass
    {
        public static void Main (string[] args)
        {
            string[] tmp = new string[2];
            tmp = Console.ReadLine().Split(' ');
            int n = Convert.ToInt32(tmp[0]);
            int m = Convert.ToInt32(tmp[1]);

            int max = m;

            if( n >= m)
                max = n;

            int answer = 0;

            for (int a = 0; a <= max; a++)
            {
                for( int b = 0; b <= max; b++)
                {
                    if( (a*a + b == n) && (a + b*b == m))
                        answer ++;

                }

            }

            Console.WriteLine(Convert.ToString(answer));

        }
    }
}


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)
        {
            int count =0;

            String line = Console.ReadLine();
            String[] ps = line.Split(' ');
            int n = int.Parse(ps[0]);
            int m = int.Parse(ps[1]);
            for (int i = 0; i <= 1000; i++)
            {
                for (int j = 0; j <= 1000; j++)
                {
                    if ((i * i) + j == n && i + (j * j) == m)
                        count++;
                }

            }
            Console.WriteLine(count);
        }
    }
}


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

namespace CF
{
    class Program
    {

        static long[] values;

        static void Main(string[] args)
        {

#if DEBUG
            TextReader reader = new StreamReader("../../input.txt");

#else
            TextReader reader = Console.In;
#endif

            //reader.ReadLine();

            values = reader.ReadLine().Split(' ').Select(i => long.Parse(i)).ToArray();

            if (F()) Console.WriteLine("First");
            else Console.WriteLine("Second");

#if DEBUG
            Console.ReadKey();
#endif

        }

        static bool F()
        {
            if (values[2] * 2 > values[1] || values[2] * 2 > values[0]) return false;
            else return true;
        }
    }
}


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

namespace Codeforces
{
    internal static class Program
    {
        private const string TEST = "C1";

        private static void Solve()
        {
            var input = ReadIntArray();
            var a = input[0];
            var b = input[1];
            var r = input[2];
            if(a >=2*r && b >= 2*r)
            {
                WriteLine("First");
            }
            else
                WriteLine("Second");
        }

        private static int Gcd(int a, int b)
        {
            if (b==0)
                return a;

            return Gcd(b, a%b);
        }

        private static void Main()
        {
            if (Debugger.IsAttached)
            {
                Console.SetIn(new StreamReader(String.Format(@"..\..\..\..\Tests\{0}.in", TEST)));
            }

            Solve();

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

        #region Reader

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

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

        private static List<int> ReadIntArray()
        {
            var input = Console.ReadLine().Split(' ').Select(Int32.Parse).ToList();
            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]);
        }

        private static double ReadDouble()
        {
            return double.Parse(Console.ReadLine(), CultureInfo.InvariantCulture);
        }

        private static List<double> ReadDoubleArray()
        {
            return Console.ReadLine().Split(' ').Select(d => double.Parse(d, CultureInfo.InvariantCulture)).ToList();
        }

        private static void WriteLine(object value)
        {
            Console.WriteLine(value);
        }

        private static void WriteLine(string value)
        {
            Console.WriteLine(value);
        }

        private static void Write(object value)
        {
            Console.Write(value);
        }

        private static void Write(string value)
        {
            Console.Write(value);
        }

        #endregion
    }
}


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

namespace CodeforcesTemplate
{
    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();

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

        static string[] _curLine;
        static int _curTokenIdx;

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

        public 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++];
        }

        public 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

            string s = Console.ReadLine();

            RunTimer();

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

                else
                {
                    break;
                }

            }

            string ss = s.Substring(0, s.Length - countZero);

            char[] r = ss.ToCharArray();

            Array.Reverse(r);

            string reverse = new string(r);

            if(reverse == ss)
            {
                Console.WriteLine("YES");
            }

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

#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

        }

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

        static string StreamReader()
        {

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

        }

        static void StreamWriter(string text)
        {

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

        }

        public 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.IO;
using System.Runtime.CompilerServices;
using System.Text;
using System.Diagnostics;
using System.Numerics;
using static System.Console;
using static System.Convert;
using static System.Math;
using static Template;
using Pi = Pair<int, int>;

class Solver
{
    public void Solve(Scanner sc)
    {
        var X = sc.Str.ToCharArray();
        Array.Reverse(X);
        var T = X.SkipWhile(c => c == '0').ToArray();
        for (int i = 0; i < T.Length / 2; i++)
            if (T[i] != T[T.Length - 1 - i]) Fail("NO");
        Console.WriteLine("YES");
    }
}

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

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

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

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


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

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

class Sol{
	public void Solve(){

		if(M==1){
			Console.WriteLine("{0} {0}",(N*(N-1))/2);
			return;
		}

		long max=((N-(M-1))*(N-(M-1)-1))/2;

		long s=N/M;
		long t=N/M+1;

		long min=(N%M)*((t*(t-1))/2)+(M-N%M)*((s*(s-1))/2);
		Console.WriteLine("{0} {1}",min,max);

	}
	long N;
	long M;
	public Sol(){
		var d=rla();
		N=d[0];M=d[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(){return Console.ReadLine().Split(' ');}
	static int[] ria(){return Array.ConvertAll(Console.ReadLine().Split(' '),e=>int.Parse(e));}
	static long[] rla(){return Array.ConvertAll(Console.ReadLine().Split(' '),e=>long.Parse(e));}
	static double[] rda(){return Array.ConvertAll(Console.ReadLine().Split(' '),e=>double.Parse(e));}
}


using System;
using System.Linq;

class Program
{
    #region utility
    static char ReadChar()
    {
        return (char)Console.Read();
    }
    static string ReadWord()
    {
        var str = string.Empty;
        while (true)
        {
            var chr = ReadChar();
            if (chr != ' ')
            {
                str += chr;
                break;
            }
        }//skip empty start
        while (true)
        {
            var chr = ReadChar();
            if (chr == ' ' || chr == '\n') break;
            str += chr;
        }
        return str;
    }
    static int ReadInt()
    {
        return int.Parse(ReadWord());
    }
    static long ReadLong()
    {
        return long.Parse(ReadWord());
    }
    #endregion

    static void Main(string[] args)
    {
        var n = ReadLong(); var m = ReadLong();

        long maxCom = GetMaxComPosses(n, m);

        long minCom = GetMinComPosses(n, m);

        Console.WriteLine($"{minCom} {maxCom}");

    }

    static long GetMinComPosses(long n, long m)
    {
        var lessTeamSize = n / m;
        var bigTeamSize = lessTeamSize + 1;

        var lessTeamCount = m - (n % m);
        var bigTeamCount = m - lessTeamCount;

        var minCom = (lessTeamCount * SumUntil(lessTeamSize)) + (bigTeamCount * SumUntil(bigTeamSize));
        return minCom;
    }

    static long GetMaxComPosses(long n, long m)
    {
        var bigTeam = n - m + 1; //all of other team will have one player, but this wil have the rest
        var maxCom = SumUntil(bigTeam);
        return maxCom;
    }

    static long SumUntil(long n)
    {
        return (n * (n - 1)) / 2;
    }
}


using System;

namespace CFB
{
    class Program
    {
        static void Main(string[] args)
        {
            ulong a, b;
            string[] inp = Console.ReadLine().Split(' ');
            a = ulong.Parse(inp[0]);
            b = ulong.Parse(inp[1]);

            odin:
            if (a == 0 || b == 0)
            {
                Console.Write(a + " " + b);
                Environment.Exit(0);
            } else goto dva;

            dva:
            if (a >= 2 * b)
            {
                ulong c = a / (2 * b);
                a -= 2 * b * c;
                goto odin;
            }
            else goto tri;

            tri:
            if (b >= 2 * a)
            {
                ulong c = b / (2 * a);
                b -= 2 * a * c;
                goto odin;
            }
            else
            {
                Console.Write(a + " " + b);
                Environment.Exit(0);
            }

        }
    }
}


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

namespace Problem946B
{
    class Program
    {
        static void Main(string[] args)
        {
            var pars = Console.ReadLine().Split(' ').Select(_ => long.Parse(_)).ToArray();
            long a = pars[0], b = pars[1];
            while (a != 0 && b != 0)
            {
                if (a >= 2 * b)
                {
                    a = a % (2 * b);
                }
                else if (b >= 2 * a)
                {
                    b = b % (2 * a);
                }
                else
                    break;
            }
            Console.WriteLine("{0} {1}", a, b);
        }
    }
}


using System;

namespace CSharp
{
    public class _820A
    {
        public static void Main()
        {
            string[] tokens = Console.ReadLine().Split();

            int c = int.Parse(tokens[0]);
            int v0 = int.Parse(tokens[1]);
            int v1 = int.Parse(tokens[2]);
            int a = int.Parse(tokens[3]);
            int l = int.Parse(tokens[4]);

            for (int day = 1, v = v0, read = v; ; day++, v = Math.Min(v + a, v1), read = Math.Max(0, read - l) + v)
            {
                if (read >= c)
                {
                    Console.WriteLine(day);
                    break;
                }
            }
        }
    }
}


using System;
namespace CodeForces {
    class Solve820A {
        int c, v0, v1, a, l;
        int days;

        public void readInput() {
            var parts = Console.ReadLine().Split(' ');
            this.c = int.Parse(parts[0]);
            this.v0 = int.Parse(parts[1]);
            this.v1 = int.Parse(parts[2]);
            this.a = int.Parse(parts[3]);
            this.l = int.Parse(parts[4]);
        }

        public void printAnswer() {
            Console.WriteLine(this.days);
        }

        public void solve() {
            this.days = 1;
            int pagesRead = this.v0;
            while (pagesRead < this.c) {
                int theoreticalSpeed = this.v0 - this.l + this.days * this.a;
                pagesRead += Math.Min(theoreticalSpeed, this.v1 - l);
                this.days++;
            }
        }
    }

    class Runner {
        public static void Main() {
            Solve820A solver = new Solve820A();
            solver.readInput();
            solver.solve();
            solver.printAnswer();
        }
    }
}


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

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.ReadLine();
            string y = Console.ReadLine();
            string y1 = y;
            string y2 = y1;
            y2 = y2.ToLower();
            string[] s = y.Split(' ');
            string[] s1 = y2.Split(' ');
            int[] mass = new int[s.Length];
            for (int i = 0; i < s.Length; i++)
            {
                for (int j = 0; j < s[i].Length; j++)
                {
                    if (s[i][j] != s1[i][j])
                    {
                        mass[i]++;
                    }
                }
            }
            Array.Sort(mass);
            Console.WriteLine(mass[mass.Length - 1]);
        }
    }
}


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

public sealed partial class Program
{
    public void EntryPoint()
    {
        var n = scanner.N();
        var v = scanner.Words(word => word.Count(char.IsUpper)).Max();
        WriteLine(v);
    }
}

#region Custom Library
public static class TemplateExtension
{
    public static X[] MakeArray<X>(this int count, Func<int, X> func)
    {
        var xs = new X[count];
        for (var i = 0; i < count; i++)
        {
            xs[i] = func(i);
        }
        return xs;
    }

    public static int[] Range(this int count, int start = 0)
    {
        return count.MakeArray(i => i + start);
    }

    public static string Intercalate<X>(this IEnumerable<X> @this, string separator)
    {
        return string.Join(separator, @this);
    }

    public static void ForEach<X>(this IEnumerable<X> @this, Action<X, int> action)
    {
        var list = @this as IReadOnlyList<X>;
        if (list != null)
        {
            var count = list.Count;
            for (var i = 0; i < count; i++)
            {
                action(list[i], i);
            }
        }
        else
        {
            var i = 0;
            foreach (var x in @this)
            {
                action(x, i);
                i++;
            }
        }
    }
}

public sealed class Scanner
{
    readonly TextReader reader;

    /// <summary>
    /// Reads next word separated by spaces.
    /// </summary>
    public string Word()
    {
        var sb = default(StringBuilder);
        var firstChar = default(char);
        var count = 0;

        while (true)
        {
            var r = reader.Read();

            if (r == '\r')
            {
                if (reader.Peek() == '\n') reader.Read();
                break;
            }
            else if (r == -1 || r == ' ' || r == '\n')
            {
                break;
            }
            else
            {
                var c = (char)r;

                switch (count)
                {
                    case 0:
                        firstChar = c;
                        count = 1;
                        break;
                    case 1:
                        sb = new StringBuilder();
                        sb.Append(firstChar).Append(c);
                        count = 2;
                        break;
                    default:
                        sb.Append(c);
                        break;
                }
            }
        }

        switch (count)
        {
            case 0:
                return "";
            case 1:
                return firstChar.ToString();
            default:
                return sb.ToString();
        }
    }

    /// <summary>
    /// Reads next word as <see cref="int"/>.
    /// </summary>
    public int N()
    {
        return int.Parse(Word());
    }

    /// <summary>
    /// Reads next word as <see cref="long"/>.
    /// </summary>
    public long L()
    {
        return long.Parse(Word());
    }

    /// <summary>
    /// Reads next word as <see cref="double"/>.
    /// </summary>
    public double F()
    {
        return double.Parse(Word());
    }

    public int[] Ns(int count)
    {
        return count.MakeArray(_ => N());
    }

    public long[] Ls(int count)
    {
        return count.MakeArray(_ => L());
    }

    public double[] Fs(int count)
    {
        return count.MakeArray(_ => F());
    }

    /// <summary>
    /// Reads next line and splits it by spaces.
    /// </summary>
    public X[] Words<X>(Func<string, X> func)
    {
        return reader.ReadLine().Split(' ').Select(func).ToArray();
    }

    public Scanner(TextReader reader)
    {
        this.reader = reader;
    }
}

public partial class Program
{
    readonly TextReader input;
    readonly TextWriter output;
    readonly Scanner scanner;

    void WriteLine(int value)
    {
        output.WriteLine(value);
    }

    void WriteLine(long value)
    {
        output.WriteLine(value);
    }

    void WriteLine(double value)
    {
        output.WriteLine(value);
    }

    void WriteLine(char value)
    {
        output.WriteLine(value);
    }

    void WriteLine(string value)
    {
        output.WriteLine(value);
    }

    public Program(TextReader input, TextWriter output)
    {
        this.input = input;
        this.output = output;
        scanner = new Scanner(input);
    }

    public static void Main(string[] args)
    {
#if DEBUG
        using (var writer = new VainZero.IO.DebugTextWriter(Console.Out))
#else
        var writer = Console.Out;
#endif
        {
            new Program(Console.In, writer).EntryPoint();
        }
    }
}
#endregion


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

namespace B
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] line = Console.ReadLine().Split(' ');
            int n = int.Parse(line[0]);
            int m = int.Parse(line[1]) - 1; // rabbit
            int k = int.Parse(line[2]) - 1;
            int dir = Console.ReadLine() == "to tail" ? 1 : -1;
            string s = Console.ReadLine();

            if (k == 0)
                dir = 1;
            if (k == n - 1)
                dir = -1;

            bool rabbitbefore = m < k;
            bool caught = false;
            int time = 0;
            for (; time < s.Length; time++)
            {
                k += dir;

                if (s[time] == '1')
                {
                    rabbitbefore = (dir == 1);
                }
                else
                {
                    if (k == 0 && rabbitbefore || k == n - 1 && !rabbitbefore)
                    {
                        caught = true;
                        break;
                    }
                }

                if (k == 0 || k == n - 1)
                    dir = -dir;
            }

            if(caught)
                Console.WriteLine("Controller {0}", time + 1);
            else
                Console.WriteLine("Stowaway");
        }
    }
}


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

namespace B
{
    class Program
    {
        static void Main(string[] args)
        {
            var tmp = Console.ReadLine().Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
            int n = int.Parse(tmp[0]);
            int zayc = int.Parse(tmp[1]);
            int controller = int.Parse(tmp[2]);
            int minut = -5;
            string naprav = Console.ReadLine();
            int znak = 0;
            if (naprav == "to head")
            {
                znak = -1;
            }
            else
            {
                znak = 1;
            }

            string mask = Console.ReadLine();
            bool win = true;

            for (int i = 0; i < mask.Length; i++)
            {
                if ((controller == 1) && (znak == -1))
                {
                    znak = -znak;
                }
                if ((controller == n) && (znak == 1))
                {
                    znak = -znak;
                }
                if (mask[i] == '0')
                {
                    if (zayc == 1 || zayc == n)
                    {

                    }
                    else
                    {
                        if (zayc < controller)
                            zayc--;
                        else
                            zayc++;
                    }
                    controller += znak;
                    if (controller == zayc)
                    {
                        win = false;
                        minut = i+1;
                        break;
                    }

                }
                else
                {
                    controller += znak;
                    if (znak == 1)
                    {
                        if (controller == 1)
                        {
                            zayc = n;
                        }
                        if (controller == n)
                        {
                            zayc = 1;
                        }
                        if(controller !=1)
                            if(controller !=n)
                        {
                            zayc = 1;
                        }
                    }
                    else
                    {
                        if (controller == n)
                        {
                            zayc = 1;
                        }
                        if (controller == 1)
                        {
                            zayc = n;
                        }
                        if (controller != 1)
                            if (controller != n)
                        {
                            zayc = n;
                        }
                    }
                }

            }

            if (win)
            {
                Console.WriteLine("Stowaway");
            }
            else
            {
                Console.WriteLine("Controller " + minut);
            }
            Console.ReadLine();
        }
    }
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Threading;
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;

class Solver
{
    public Scanner sc;
    public void Solve()
    {
        long N, M;
        sc.Make(out N, out M);
        var min = Max(0, N - 2 * M);
        int i;var now = 0L;
        if (M == 0) Fail($"{min} {N}");
        for (i = 0; i < N; i++)
        {
            now += i;
            if (now >= M) break;
        }
        Console.WriteLine($"{min} {N-i-1}");
    }
}

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

#endregion


using System;
using System.Collections.Generic;

namespace G6
{
    class Program
    {
        static void Main(string[] args)
        {
            long n, m;
            string[] sins = Console.ReadLine().Trim(' ').Split(' ');
            n = long.Parse(sins[0]);
            m = long.Parse(sins[1]);

            if (n != 1)
            {
                if (m != 0)
                {
                    long summ = 1;
                    long answerMax = n - 2;
                    for (int i = 2; i <= n; i++)
                    {
                        if (summ < m)
                        {
                            answerMax--;
                        }
                        else
                        {
                            break;
                        }
                        summ += i;
                    }

                    long AnswerMin = 0;
                    if (n % 2 == 0)
                    {
                        if (m < n / 2)
                            AnswerMin = n - m * 2;
                    }
                    else
                    {
                        if (m < (n + 1) / 2)
                            AnswerMin = n - m * 2;
                    }
                    Console.Write(AnswerMin + " " + answerMax);
                }
                else
                {
                    Console.Write(n + " " + n);
                }
            }
            else
            {
                Console.Write("1 1");
            }
            //Console.ReadKey();
        }
    }
}


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

namespace ConsoleApp7
{
    class Program
    {
        static void Main(string[] args)
        {
            var n = Console.ReadLine().Int();
            var a = Console.ReadLine().Int();
            var b = Console.ReadLine().Int();
            var c = Console.ReadLine().Int();
            int total = 0;
            int ate = 1;
            if (n == ate)
            {
                Console.WriteLine(0);
                return;
            }
            var l = new List<int>
            {
                a,
                b,
                c
            };

            l = l.OrderBy(u => u).ToList();
            if (l[0] == a || l[0] == b)
            {
                n -= 1;
                Console.WriteLine(n * l[0]);
            }
            else
            {
                n -= 2;
                total += Math.Min(a, b);
                Console.WriteLine(total + n * l[0]);
            }
        }
    }
    static class H
    {
        public static int Int(this string str)
        {
            return int.Parse(str);
        }
    }
}


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

namespace CodeforcesTemplate
{
    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
            int k, i = 0, s = 1, sum = 0, p = 1;

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

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

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

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

            while (s != n)
            {
                if (p == 1)
                {
                    if (ks < ko)
                    {
                        sum = sum + ks;
                        s++;
                        p = 3;
                    }
                    else
                    {
                        sum = sum + ko;
                        s++;
                        p = 2;
                    }
                }

                else if (p == 2)
                {
                    if (ko < so)
                    {
                        sum = sum + ko;
                        s++;
                        p = 1;
                    }

                    else
                    {
                        sum = sum + so;
                        s++;
                        p = 3;
                    }
                }

                else if (p == 3)
                {
                    if (so < ks)
                    {
                        sum = sum + so;
                        s++;
                        p = 2;
                    }
                    else
                    {
                        sum = sum + ks;
                        s++;
                        p = 1;
                    }
                }

            }

            Console.WriteLine(sum);

#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.Text;
using System.Collections.Generic;
using System.Linq;
class Solve{
    public Solve(){}
    StringBuilder sb;
    ReadData re;
    public static int Main(){
        new Solve().Run();
        return 0;
    }
    void Run(){
        sb = new StringBuilder();
        re = new ReadData();
        Calc();
        Console.Write(sb.ToString());
    }
    void Calc(){
        int K = re.i();
        int A = 0;
        for(int i=0;i<K;i++){
            A = Math.Max(A,re.i());
        }
        int count = Math.Max(0,A-25);
        sb.Append(count+"\n");
    }
}
class ReadData{
    string[] str;
    int counter;
    public ReadData(){
        counter = 0;
    }
    public string s(){
        if(counter == 0){
            str = Console.ReadLine().Split(' ');
            counter = str.Length;
        }
        counter--;
        return str[str.Length-counter-1];
    }
    public int i(){
        return int.Parse(s());
    }
    public long l(){
        return long.Parse(s());
    }
    public double d(){
        return double.Parse(s());
    }
    public int[] ia(int N){
        int[] ans = new int[N];
        for(int j=0;j<N;j++){
            ans[j] = i();
        }
        return ans;
    }
    public int[] ia(){
        str = Console.ReadLine().Split(' ');
        counter = 0;
        int[] ans = new int[str.Length];
        for(int j=0;j<str.Length;j++){
            ans[j] = int.Parse(str[j]);
        }
        return ans;
    }
    public long[] la(int N){
        long[] ans = new long[N];
        for(int j=0;j<N;j++){
            ans[j] = l();
        }
        return ans;
    }
    public long[] la(){
        str = Console.ReadLine().Split(' ');
        counter = 0;
        long[] ans = new long[str.Length];
        for(int j=0;j<str.Length;j++){
            ans[j] = long.Parse(str[j]);
        }
        return ans;
    }
    public double[] da(int N){
        double[] ans = new double[N];
        for(int j=0;j<N;j++){
            ans[j] = d();
        }
        return ans;
    }
    public double[] da(){
        str = Console.ReadLine().Split(' ');
        counter = 0;
        double[] ans = new double[str.Length];
        for(int j=0;j<str.Length;j++){
            ans[j] = double.Parse(str[j]);
        }
        return ans;
    }
    public List<int>[] g(int N,int[] f,int[] t){
        List<int>[] ans = new List<int>[N];
        for(int j=0;j<N;j++){
            ans[j] = new List<int>();
        }
        for(int j=0;j<f.Length;j++){
            ans[f[j]].Add(t[j]);
            ans[t[j]].Add(f[j]);
        }
        return ans;
    }
    public List<int>[] g(int N,int M){
        List<int>[] ans = new List<int>[N];
        for(int j=0;j<N;j++){
            ans[j] = new List<int>();
        }
        for(int j=0;j<M;j++){
            int f = i()-1;
            int t = i()-1;
            ans[f].Add(t);
            ans[t].Add(f);
        }
        return ans;
    }
    public List<int>[] g(){
        int N = i();
        int M = i();
        List<int>[] ans = new List<int>[N];
        for(int j=0;j<N;j++){
            ans[j] = new List<int>();
        }
        for(int j=0;j<M;j++){
            int f = i()-1;
            int t = i()-1;
            ans[f].Add(t);
            ans[t].Add(f);
        }
        return ans;
    }
}
public static class Define{
    public const long mod = 1000000007;
}
public static class Debug{
    public static void Print(double[,,] k){
        for(int i=0;i<k.GetLength(0);i++){
            for(int j=0;j<k.GetLength(1);j++){
                for(int l=0;l<k.GetLength(2);l++){
                    Console.Write(k[i,j,l]+" ");
                }
                Console.WriteLine();
            }
            Console.WriteLine();
        }
    }
    public static void Print(double[,] k){
        for(int i=0;i<k.GetLength(0);i++){
            for(int j=0;j<k.GetLength(1);j++){
                Console.Write(k[i,j]+" ");
            }
            Console.WriteLine();
        }
    }
    public static void Print(double[] k){
        for(int i=0;i<k.Length;i++){
            Console.WriteLine(k[i]);
        }
    }
    public static void Print(long[,,] k){
        for(int i=0;i<k.GetLength(0);i++){
            for(int j=0;j<k.GetLength(1);j++){
                for(int l=0;l<k.GetLength(2);l++){
                    Console.Write(k[i,j,l]+" ");
                }
                Console.WriteLine();
            }
            Console.WriteLine();
        }
    }
    public static void Print(long[,] k){
        for(int i=0;i<k.GetLength(0);i++){
            for(int j=0;j<k.GetLength(1);j++){
                Console.Write(k[i,j]+" ");
            }
            Console.WriteLine();
        }
    }
    public static void Print(long[] k){
        for(int i=0;i<k.Length;i++){
            Console.WriteLine(k[i]);
        }
    }
    public static void Print(int[,,] k){
        for(int i=0;i<k.GetLength(0);i++){
            for(int j=0;j<k.GetLength(1);j++){
                for(int l=0;l<k.GetLength(2);l++){
                    Console.Write(k[i,j,l]+" ");
                }
                Console.WriteLine();
            }
            Console.WriteLine();
        }
    }
    public static void Print(int[,] k){
        for(int i=0;i<k.GetLength(0);i++){
            for(int j=0;j<k.GetLength(1);j++){
                Console.Write(k[i,j]+" ");
            }
            Console.WriteLine();
        }
    }
    public static void Print(int[] k){
        for(int i=0;i<k.Length;i++){
            Console.WriteLine(k[i]);
        }
    }
}


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

namespace NetExperiment
{
    class Program
    {
        static void Main(string[] args)
        {
            int k = int.Parse(Console.ReadLine());
            int[] r = Console.ReadLine().Split().Select(s => int.Parse(s)).ToArray();
            int max = r.Max();
            if (max > 25)
                Console.WriteLine(max - 25);
            else
                Console.WriteLine(0);
        }
    }
}


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

namespace CodeforcesSolution
{
    class ProgramCF
    {
        static ConsoleInput inp;
        static void Main( string[] args )
        {
            try
            {
                if ( File.Exists( @"d:\zin.txt" ) )
                    Console.SetIn( new StreamReader( @"d:\zin.txt" ) );
            }
            catch
            {
            }
            inp = new ConsoleInput();
            inp.ReadAll();

            int N = inp.NextInt();
            List<int> f = new List<int>();

            for ( int i = 0; i < N; i++ )
            {
                f.Add( 1 );
                while ( f.Count > 1 )
                {
                    if ( f[f.Count - 1] == f[f.Count - 2] )
                    {
                        f.RemoveAt( f.Count - 1 );
                        f[f.Count - 1] += 1;
                    }
                    else
                        break;
                }
            }
            Console.WriteLine( string.Join( " ", f.Select( n => n.ToString() ).ToArray() ) );

            // end here
            // ====
            //WriteLine ( "" );
        }

        private static bool IsPalindromic( long n )
        {
            string s = n.ToString();
            for ( int i = 0; i < s.Length; i++ )
            {
                int j = s.Length - i - 1;
                if ( s[i] != s[j] )
                    return false;
            }
            return true;
            //string srev = new string ( s.ToCharArray ( ).Reverse ( ).ToArray ( ) );
            //return ( s.Equals ( srev ) );
        }

        //====================================================//
        private static void WriteLine( params object[] value )
        {
            Console.WriteLine( string.Format( CultureInfo.InvariantCulture, "{0}", value ) );
        }

        class ConsoleInput
        {
            List<string> lines = new List<string>();
            int idx = 0;

            public void ReadAll()
            {
                while ( true )
                {
                    string line = Console.ReadLine();
                    if ( line == null )
                        break;
                    lines.AddRange( line.Split( ' ' ) );
                }
            }

            public string NextString()
            {
                return lines[idx++];
            }

            public int NextInt()
            {
                return int.Parse( lines[idx++] );
            }

            public long NextLong()
            {
                return long.Parse( lines[idx++] );
            }

            public double NextDouble()
            {
                return double.Parse( lines[idx++] );
            }

        }

    }
}


using System;
using System.Linq;
using System.Collections.Generic;
//using System.Numerics;
using Debug = System.Diagnostics.Debug;
using SB = System.Text.StringBuilder;
using Number = System.Int64;
namespace Program {
    public class Solver {
        public void Solve() {
            var n = ri;
            var a = new List<int>();
            for (int i = 20; i >= 0; i--)
                if ((n >> i & 1) == 1) {
                    a.Add(i + 1);
                }
            Console.WriteLine(a.AsJoinedString());

        }
        const long INF = 1L << 60;
        int[] dx = { -1, 0, 1, 0 };
        int[] dy = { 0, 1, 0, -1 };

        int ri { get { return sc.Integer(); } }
        long rl { get { return sc.Long(); } }
        double rd { get { return sc.Double(); } }
        string rs { get { return sc.Scan(); } }
        public IO.StreamScanner sc = new IO.StreamScanner(Console.OpenStandardInput());

        static T[] Enumerate<T>(int n, Func<int, T> f) {
            var a = new T[n];
            for (int i = 0; i < n; ++i) a[i] = f(i);
            return a;
        }

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

#region main

static class Ex {
    static public string AsString(this IEnumerable<char> ie) {
        return new string(ie.ToArray());
    }

    static public string AsJoinedString<T>(this IEnumerable<T> ie, string st = " ") {
        return string.Join(st, ie.Select(x => x.ToString()).ToArray());
        //return string.Join(st, ie);
    }

    static public void Main() {
        Console.SetOut(new Program.IO.Printer(Console.OpenStandardOutput()) { AutoFlush = false });
        var solver = new Program.Solver();
        solver.Solve();
        Console.Out.Flush();
    }
}

#endregion
#region Ex

namespace Program.IO {
    using System.IO;
    using System.Text;
    using System.Globalization;

    public class Printer: StreamWriter {
        public override IFormatProvider FormatProvider {
            get { return CultureInfo.InvariantCulture; }
        }
        public Printer(Stream stream) : base(stream, new UTF8Encoding(false, true)) { }
    }

    public class StreamScanner {
        public StreamScanner(Stream stream) {
            str = stream;
        }

        public readonly Stream str;
        private readonly byte[] buf = new byte[1024];
        private int len, ptr;
        public bool isEof = false;
        public bool IsEndOfStream {
            get { return isEof; }
        }

        private byte read() {
            if (isEof) return 0;
            if (ptr >= len) {
                ptr = 0;
                if ((len = str.Read(buf, 0, 1024)) <= 0) {
                    isEof = true;
                    return 0;
                }
            }
            return buf[ptr++];
        }

        public char Char() {
            byte b = 0;
            do b = read(); while ((b < 33 || 126 < b) && !isEof);
            return (char)b;
        }

        public string Scan() {
            var sb = new StringBuilder();
            for (var b = Char(); b >= 33 && b <= 126; b = (char)read()) sb.Append(b);
            return sb.ToString();
        }

        public string ScanLine() {
            var sb = new StringBuilder();
            for (var b = Char(); b != '\n' && b != 0; b = (char)read()) if (b != '\r') sb.Append(b);
            return sb.ToString();
        }

        public long Long() {
            return isEof ? long.MinValue : long.Parse(Scan());
        }

        public int Integer() {
            return isEof ? int.MinValue : int.Parse(Scan());
        }

        public double Double() {
            return isEof ? double.NaN : double.Parse(Scan(), CultureInfo.InvariantCulture);
        }
    }
}

#endregion


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

public class Program
{
    public void Solve()
    {
        var sc = new Scanner();
        long n = sc.NextLong();
        int k = sc.NextInt();
        List<long> div = new List<long>();
        for (long i = 1; i * i <= n; i++)
        {
            if (n % i == 0)
            {
                div.Add(i);
                if (n / i != i) div.Add(n / i);
            }
        }

        if (div.Count < k)
        {
            Console.WriteLine("-1");
            return;
        }

        div.Sort();

        Console.WriteLine(div[k - 1]);
    }

    public static void Main(string[] args) => new Program().Solve();
    // public static void Main(string[] args) => new Thread(new Program().Solve, 1 << 27).Start();
}

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

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

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

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

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

            return _line[_index++];
        }

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

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

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

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


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

namespace ааа
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] num = Console.ReadLine().Split(' ');
            Int64 n = Int64.Parse(num[0]);
            Int32 k = Int32.Parse(num[1]);
           Int64 End =Convert.ToInt64(Math.Sqrt(n));
           List<Int64> spisok = new List<Int64>();
           for (int i = 1; i <= End; i++)
           {
               if (n%i==0)
               {
                   spisok.Add(i);
                   if (i != (n / i))
                   {
                       spisok.Add(n / i);
                   }
               }
           }
           if (spisok.Count < k)
           {
               Console.WriteLine(-1);
           }
           else
           {
               spisok.Sort();
               Console.WriteLine(spisok.ElementAt(k-1));
           }

          // Console.ReadKey();
        }
    }
}


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

namespace TaskD
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            switch (n)
            {
                case 1: { Console.Write("2"); break; }
                case 2: { Console.Write("3"); break; }
                case 3: { Console.Write("1"); break; }
                case 4: { Console.Write("2"); break; }
                case 5: { Console.Write("1"); break; }
            }
        }
    }
}


using System;

namespace _171D
{
    class Program
    {
        static void Main()
        {
            var n = int.Parse(Console.ReadLine());
            switch(n)
            {
                case 1:
                    Console.WriteLine(2);
                    break;
                case 2:
                    Console.WriteLine(3);
                    break;
                case 3:
                    Console.WriteLine(1);
                    break;
                case 4:
                    Console.WriteLine(2);
                    break;
                case 5:
                    Console.WriteLine(1);
                    break;
            }
        }
    }
}


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

namespace TaskA
{
    class Program
    {
        static void Main(string[] args)
        {
            var input = Console.ReadLine().Split(' ');
            int t = int.Parse(input[0]);
            int s = int.Parse(input[1]);
            int x = int.Parse(input[2]);

            if (x < t)
            {
                Console.WriteLine("NO");
                return;
            }

            if (t == x)
            {
                Console.WriteLine("YES");
                return;
            }

            int dif = x - t;

            if (dif % s == 0 || ((dif - 1) > 0 && (dif - 1) % s == 0))
            {
                Console.WriteLine("YES");
                return;
            }

            Console.WriteLine("NO");
            Console.ReadLine();
        }
    }
}


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

namespace _697A
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] input = Console.ReadLine().Split(' ');
            decimal t = decimal.Parse(input[0]), s = decimal.Parse(input[1]), x = decimal.Parse(input[2]);
            decimal k1 = (x - t) / s;
            decimal k2 = (x - t - 1) / s;
            bool result = (k1 >= 0 && decimal.Compare(k1, Math.Truncate(k1)) == 0) ||
                (k2 >= 1 && decimal.Compare(k2, Math.Truncate(k2)) == 0);
            Console.WriteLine(result ? "YES" : "NO");
            //Console.ReadLine();
        }
    }
}