You are given two integers n and k. Find k-th smallest divisor of n, or report that it doesn't exist.Divisor of n is any such natural number, that n can be divided by it without remainder.

The first line contains two integers n and k (1 ≤ n ≤ 1015, 1 ≤ k ≤ 109).

If n has less than k divisors, output -1. Otherwise, output the k-th smallest divisor of n.

NoteIn the first example, number 4 has three divisors: 1, 2 and 4. The second one is 2.In the second example, number 5 has only two divisors: 1 and 5. The third divisor doesn't exist, so the answer is -1.

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

namespace Olymp
{
  public class ProblemSolver
  {
    private Tokenizer input;

    public void Solve()
    {
      long n = input.NextLong();
      int k = input.NextInt();
      long last = (long)Math.Sqrt(n);
      int c = 0;
      for (long i = 1; i <= last; i++)
      {
        if (n % i == 0)
        {
          c++;
          if (c == k)
          {
            Console.Write(i);
            return;
          }
        }
      }
      if (last * last == n)
      {
        last--;
      }
      for (long i = last; i > 0; i--)
      {
        if (n % i == 0)
        {
          c++;
          if (c == k)
          {
            Console.Write(n / i);
            return;
          }
        }
      }
      Console.Write(-1);
    }

    public ProblemSolver(TextReader input)
    {
      this.input = new Tokenizer(input);
    }
  }

  #region Service classes

  public class Tokenizer
  {
    private TextReader reader;

    public int NextInt()
    {
      var c = SkipWS();
      if (c == -1)
        throw new EndOfStreamException();
      bool isNegative = false;
      if (c == '-' || c == '+')
      {
        isNegative = c == '-';
        c = this.reader.Read();
        if (c == -1)
          throw new InvalidOperationException();
      }
      if (!char.IsDigit((char)c))
        throw new InvalidOperationException();
      int result = (char)c - '0';
      c = this.reader.Read();
      while (c > 0 && !char.IsWhiteSpace((char)c))
      {
        if (!char.IsDigit((char)c))
          throw new InvalidOperationException();
        result = result * 10 + (char)c - '0';
        c = this.reader.Read();
      }
      if (isNegative)
        result = -result;
      return result;
    }

    public string ReadLine()
    {
      return reader.ReadLine();
    }

    public long NextLong()
    {
      return long.Parse(this.NextToken());
    }

    public double NextDouble()
    {
      return double.Parse(this.NextToken(), CultureInfo.InvariantCulture);
    }

    public int[] ReadIntArray(int n)
    {
      int[] a = new int[n];
      for (int i = 0; i < n; i++)
        a[i] = NextInt();
      return a;
    }

    public long[] ReadLongArray(int n)
    {
      long[] a = new long[n];
      for (int i = 0; i < n; i++)
        a[i] = NextLong();
      return a;
    }

    public double[] ReadDoubleArray(int n)
    {
      double[] a = new double[n];
      for (int i = 0; i < n; i++)
        a[i] = NextDouble();
      return a;
    }

    public string NextToken()
    {
      var c = SkipWS();
      if (c == -1)
        return null;
      var sb = new StringBuilder();
      while (c > 0 && !char.IsWhiteSpace((char)c))
      {
        sb.Append((char)c);
        c = this.reader.Read();
      }
      return sb.ToString();
    }

    private int SkipWS()
    {
      int c = this.reader.Read();
      if (c == -1)
        return c;
      while (c > 0 && char.IsWhiteSpace((char)c))
        c = this.reader.Read();
      return c;
    }

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

  class Program
  {
    public static void Main(string[] args)
    {
      var solver = new ProblemSolver(Console.In);
      solver.Solve();
    }
  }

  #endregion
}

using System;
using System.Collections.Generic;

public class Program
{
    static void Main(string[] args)
    {
        string[] ip = Console.ReadLine().Split();
        long n = long.Parse(ip[0]);
        int k = int.Parse(ip[1]);
        var lower = new List<long>();
        var higher = new List<long>();
        long i;
        for(i = 1; i * i < n; i++)
        {
            if(n % i == 0)
            {
                lower.Add(i);
                higher.Add(n / i);
            }
        }
        if(i * i == n)
        {
            lower.Add(i);
        }
        higher.Sort();
        long ans;
        if(k <= lower.Count)
        {
            ans = lower[k - 1];
        }
        else if(k <= lower.Count + higher.Count)
        {
            ans = higher[k - lower.Count - 1];
        }
        else
        {
            ans = -1;
        }
        Console.WriteLine(ans);
    }
}

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

namespace Codeforces
{
  class Program
  {
    static void Main(string[] args)
    {
      var cin = Console.ReadLine().Split(' ');

      long n = long.Parse(cin[0]);
      int k = int.Parse(cin[1]);

      var d = new List<long>();

      for (int i = 1; i <= Math.Sqrt(n); i++)
      {
        if (n % i == 0)
        {
          d.Add(i);
        }
      }

      int s = d.Count();

      for (int i = 0; i < s; i++)
      {
        if (d[i] == Math.Sqrt(n)) { continue; }
        d.Add(n / d[i]);
      }

      d.Sort();

      long r = k <= d.Count() ? d[k - 1] : -1;

      Console.WriteLine(r);
    }
  }
}

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

namespace kdivisor
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] s = Console.ReadLine().Split();

            long n = long.Parse(s[0]);
            int k = int.Parse(s[1]);

            long lim =(long) Math.Sqrt(n);

            long ans = -1;
            int count = 0;
            List<long> divisors = new List<long>();

            for (long i=1;i<=lim;i++)
            {
                if (n%i==0)
                {
                    count++;
                    if (count==k)
                    {
                        ans = i;
                        break;
                    }
                   if (n/i!=i) divisors.Insert(0, n / i);
                }
            }

            if (ans == -1 && count + divisors.Count >= k) ans = divisors[k-count-1];

            Console.Write(ans);
         }
    }
}

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

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

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

            var l = new List<long>();
            var o = new Stack<long>();

            for (long i = 1;; i++)
            {
                if (i*i >= n)
                {
                    if (i*i == n)
                        l.Add(i);
                    break;
                }
                if (n%i == 0)
                {
                    l.Add(i);
                    o.Push(n/i);
                }
            }
            l.AddRange(o);

            if (k < l.Count)
                writer.WriteLine(l[(int) k]);
            else writer.WriteLine("-1");

            writer.Flush();
        }

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

using System;
using System.Collections.Generic;

namespace _762A
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] input = Console.ReadLine().Split(' ');
            long n = long.Parse(input[0]), k = long.Parse(input[1]) - 1;
            List<long> factors = new List<long>();
            long max = (long)Math.Sqrt(n);
            for (long factor = 1; factor <= max; ++factor)
            {
                if (n % factor == 0)
                {
                    factors.Add(factor);
                    if (factor != n / factor)
                    {
                        factors.Add(n / factor);
                    }
                }
            }
            factors.Sort();
            if (factors.Count < k + 1)
                Console.WriteLine("-1");
            else
                Console.WriteLine(factors[(int)k]);
        }
    }
}

using System;

namespace CodeForces5
{
	class Program
	{
		static void Main(string[] args)
		{
			string[] Data = Console.ReadLine().Split(' ');
			long[] data = Array.ConvertAll(Data, x => long.Parse(x));
			long count = 0, result = 0;
			for (long i = 1; i <= (int)Math.Sqrt(data[0]); i++)
				if (data[0] % i == 0)
					if (++count == data[1])
					{
						result = i;
						break;
					}
			if (count != data[1])
			{
				long del = 2 * count;
				if ((int)Math.Sqrt(data[0]) == Math.Sqrt(data[0])) del--;
				if (del < data[1]) result = -1;
				else
				{
					for (long i = 1, newcount = 0; newcount <= del - data[1] + 1; i++)
					{
						if (data[0] % i == 0)
						{
							newcount++;
							if (newcount == del - data[1] + 1)
							{
								result = data[0] / i;
								break;
							}
						}

					}
				}
			}

			Console.WriteLine(result);
		}
	}
}

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

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

				//Console.ReadKey();
			}
		}
	}

	internal class Task
	{
		public void Solve(InputReader sr, TextWriter sw)
		{
			var input = sr.ReadArray(Int64.Parse);
			var n = input[0];
			var k = input[1];
			var div1 = new List<long>();
			var div2 = new List<long>();
			for (var i = 1L; i * i <= n; i++) {
				if (n % i == 0) {
					div1.Add(i);
					div2.Add(n / i);
				}
			}
			var sortedSet = new SortedSet<long>(div1);
			sortedSet.UnionWith(div2);
			if (sortedSet.Count < k) {
				sw.WriteLine(-1);
				return;
			}
			sw.WriteLine(sortedSet.ToArray()[k - 1]);
		}
	}
}

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

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

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

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

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

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

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

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

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

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

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

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

namespace A_kth_divisor
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] input = Console.ReadLine().Split(' ');
            long n = long.Parse(input[0]);
            long k = long.Parse(input[1]);
            bool b = false;

            long sqrt = (long)(Math.Ceiling(Math.Sqrt(n)));
            if (sqrt * sqrt == n)  b = true;

            long[] divs = new long[100000];
            long[] mirror = new long[100000];
            long counter = 0;
            for (long i = 1; i < sqrt; i++)
            {
                if (n % i == 0)
                {
                    divs[counter] = i;
                    mirror[counter] = n / i;
                    counter++;
                }
            }

            if (k > (counter) * 2 + Convert.ToInt64(b)) Console.WriteLine("-1");
            else if (k <= counter) Console.WriteLine(divs[k-1]);
            else if (k == counter + 1 && b) Console.WriteLine(sqrt);
            else Console.WriteLine(mirror[(counter) * 2 + Convert.ToInt64(b) - k]);
        }
    }
}

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

namespace k_divisor
{
    class Program
    {
        static int max = 31622780;
        static int[] primes = new int[max];
        static List<long> facts = new List<long>();
        static List<long> factoring = new List<long>();
        static List<long> divisors = new List<long>();
        static void Cieve()
        {
            for (int i = 4; i < max; i += 2) primes[i] = 2;
            for (int i = 3; i * i < max; i += 2)
                if (primes[i] == -1)
                    for (int j = i * i; j < max; j += 2 * i)
                        primes[j] = i;
        }

        static void prime_fact(long n)
        {
            for (long i = 2; i < max; i++)
            {
                if (primes[i] == -1 && n % i == 0)
                    facts.Add(i);
            }
        }

        static void factorization(long n)
        {
            long aux = n;
            for (int i = 0; i < facts.Count; i++)
            {
                int c = 0;
                long v = facts[i];
                while (aux % v == 0)
                {
                    c++;
                    aux /= v;
                }
                factoring.Add(v); factoring.Add(c);
            }
            if(aux > 1){
                factoring.Add(aux);
                factoring.Add(1);
            }

        }

        static void Divisors(long n)
        {
            for (int i = 0; i < factoring.Count; i += 2)
            {
                int c = 0;
                long v = factoring[i];
                for (int k = 1; k <= factoring[i+1]; k++)
                {
                    long x = (long)Math.Pow(v, k);
                    if (x < n)
                    {
                        divisors.Add(x);
                        c++;
                    }
                    else
                        break;
                }
                int t = divisors.Count;
                for(int j = t-c; j < t; j++)
                    for(int s = 0; s < t-c; s++){
                        long aux = divisors[j]*divisors[s];
                        if(aux < n)
                            divisors.Add(aux);
                    }
            }
            divisors.Add(n);
            divisors.Insert(0, 1);
            divisors.Sort();
        }
        static void Main(string[] args)
        {
            string s = Console.ReadLine();
            char []sep= new char[]{' '};
            string[] ns = s.Split(sep,2);
            long n = long.Parse(ns[0]);
            long k = long.Parse(ns[1]);
            if (n == 1)
            {
                if(k == 1)
                    Console.WriteLine(1);
                else
                    Console.WriteLine(-1);
                return;
            }
            for (long i = 2; i < max; i++)
            {
                primes[i] = -1;
            }
            Cieve();
            prime_fact(n);
            factorization(n);
            Divisors(n);
            if (k > divisors.Count)
            {
                Console.WriteLine(-1);
                return;
            }
            int t = (int)k;
            Console.WriteLine(divisors[t-1]);
        }
    }
}

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

class cf1
{
    static void Main()
    {
        string strInfo01 = Console.ReadLine();

        long lngNumber = long.Parse(strInfo01.Split()[0]);
        long lngPosition = long.Parse(strInfo01.Split()[1]);
        long lngSquare = (long)Math.Sqrt(lngNumber);

        List<long> lstResults = new List<long>();

        for (long i = 1; i <= lngSquare; i++)
        {
            if (lngNumber % i == 0)
            {
                lstResults.Add(i);
                if (i != lngNumber/i)
                {
                    lstResults.Add(lngNumber / i);
                }
            }
        }

        lstResults.Sort();

        if (lstResults.Count< lngPosition)
        {
            Console.WriteLine(-1);
        }
        else
        {
            Console.WriteLine(lstResults [(int)lngPosition-1]);
        }
    }
}

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

namespace denemexxxx
{
    class Program
    {
        static void Main(string[] args)
        {
            try {
                string[] nk = Console.ReadLine().Split(' ');
                long n = long.Parse(nk[0]);
                long k = long.Parse(nk[1])-1;
                List<long> sayilar = new List<long>();
                long max = (long)Math.Sqrt(n);
                for (long i = 1; i <=max; ++i)
                {
                    if(n%i == 0)
                    {
                        sayilar.Add(i);
                        if (i != n / i)
                            sayilar.Add(n / i);
                    }
                }
                sayilar.Sort();
                if (sayilar.Count < k + 1)
                {
                    Console.Write(-1);
                }
                else
                    Console.Write(sayilar[(int)k]);
                Console.ReadKey();
            }
            catch { }

        }
    }
}

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

namespace denemexxxx
{
    class Program
    {
        static void Main(string[] args)
        {
            try {
                string[] nk = Console.ReadLine().Split(' ');
                long n = long.Parse(nk[0]);
                long k = long.Parse(nk[1])-1;
                List<long> sayilar = new List<long>();
                long max = (long)Math.Sqrt(n);
                for (long i = 1; i <=max; i++)
                {
                    if(n%i == 0)
                    {
                        sayilar.Add(i);
                        if (i != n / i)
                            sayilar.Add(n / i);
                    }
                }
                sayilar.Sort();
                if (sayilar.Count < k + 1)
                {
                    Console.Write(-1);
                }
                else
                    Console.Write(sayilar[(int)k]);
                Console.ReadKey();
            }
            catch { }

        }
    }
}

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

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

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

class PairVariable : IComparable<PairVariable>
{
    public decimal a, b;
    public PairVariable()
    {
        a = b = 0;
    }
    public PairVariable(string s)
    {
        string[] q = s.Split();
        a = decimal.Parse(q[0]);
        b = decimal.Parse(q[1]);
    }
    public PairVariable(decimal a, decimal b)
    {
        this.a = a;
        this.b = b;
    }

    public int CompareTo(PairVariable other)
    {
        return this.a.CompareTo(other.a);
    }
}

namespace ConsoleApplication254
{

    class Program
    {

        static void Main(string[] args)
        {
            string[] ss = Console.ReadLine().Split();
            long n = long.Parse(ss[0]);
            int m = int.Parse(ss[1]);
            List<long> d = new List<long>();
            d.Add(1);

            for (int i = 2; i <= Math.Sqrt(n); i++)
            {
                if (n % i == 0)
                {
                    d.Add(i);
                }
            }

            int x = d.Count;
            for (int i = 0; i < x; i++)
            {
                if (n % d[i] == 0)
                {
                    if (n / d[i] != d[i])
                    {
                        d.Add(n / d[i]);
                    }
                }
            }
            d.Sort();
            //d.Add(n);
            /*for (int i = 0; i < d.Count; i++)
            {
                Console.Write(d[i]+" ");
            }
            Console.WriteLine();*/
            if (m > d.Count)
            {
                Console.WriteLine(-1);
            }
            else
            {
                Console.WriteLine(d[m - 1]);
            }

        }
    }
}

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

namespace _2609cry
{
    class Program
    {
        static void Main(string[] args)
        {
            String [] str = Console.ReadLine().Split();
            Int64 n = Convert.ToInt64(str[0]);
            Int32 m = Convert.ToInt32(str[1]);

            List<long> del = new List<long>();

            for (int i = 1; i <= Math.Sqrt(n); i++)
            {
                if (n % i == 0)
                {
                    del.Add(i);
                    if (i != n / i)
                    del.Add(n / i);
                }
            }

            del.Sort();

            if (del.Count >= m)
            {
                Console.WriteLine(del[m - 1]);
            }
            else Console.WriteLine(-1);
        }
    }
}

using System;
using System.Collections.Generic;

class Program
{
    static void Main(string[] args)
    {
        string[] inputs = Console.ReadLine().Split(' ');
        Console.WriteLine(Solve(long.Parse(inputs[0]), int.Parse(inputs[1])));
    }

    static long Solve(long n, int k)
    {
        List<int> divisors = new List<int>(5000);

        for (int i = 1; (long)i * i <= n; i++)
        {
            if (n % i == 0)
                divisors.Add(i);
        }

        if (k > (divisors.Count * 2) - (IsPerfectSquare(n) ? 1 : 0))
            return -1;

        int offset = (IsPerfectSquare(n) ? 1 : 0);
        return (k <= divisors.Count) ? divisors[k - 1] : (n / divisors[2 * divisors.Count - k - offset]);
    }

    static bool IsPerfectSquare(long n)
    {
        long sq = (long)Math.Sqrt(n);
        return sq * sq == n;
    }
}

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

namespace codeforces
{
	class Program
	{
		public const int Osn = 1000000007;

		public class Pair
		{
			public long First;

			public long Second;
		}

		public class PairComparer : IComparer<Pair>
		{
			public int Compare(Pair x, Pair y)
			{
				if (x.First < y.First || (x.First == y.First && x.Second > y.Second))
					return -1;
				return 1;
			}
		}

		public static long GetGcd(long a, long b)
		{
			while (true)
			{
				if (b == 0)
					return a;
				var a1 = a;
				a = b;
				b = a1 % b;

			}
		}

		public static void WriteYesNo(bool x, string yes = "YES", string no = "NO")
		{
			if (x)
				Console.WriteLine(yes);
			else
			{
				Console.WriteLine(no);
			}
		}

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

		public static List<int> ReadListOfInts()
		{
			var s = Console.ReadLine();
			return s.Split(' ').Select(int.Parse).ToList();
		}

		public static List<long> ReadListOfLongs()
		{
			var s = Console.ReadLine();
			return s.Split(' ').Select(long.Parse).ToList();
		}

		public static int ReadInt()
		{
			var s = Console.ReadLine();
			return int.Parse(s);
		}

		public static long ReadLong()
		{
			var s = Console.ReadLine();
			return long.Parse(s);
		}

		public class Vertex
		{
			public int Was;

			public List<int> Edges;
		}

		public static List<Vertex> Graph = new List<Vertex>();

		public static bool Dfs(int u)
		{
			if (Graph[u].Was == 1) return true;
			if (Graph[u].Was == 2) return false;
			Graph[u].Was = 1;
			foreach (var t in Graph[u].Edges)
			{
				if (Dfs(t)) return true;
			}

			Graph[u].Was = 2;
			return false;
		}

		public static bool IsPrime(long x)
		{
			for (var j = 2; j * j <= x; ++j)
				if (x % j == 0)
					return false;
			return true;
		}

		public class LinkedVertex
		{
			public int Next;

			public int Prev;

			public int Value;
		}

		public static int BinarySearch(List<int> list, int value)
		{
			var l = -1;
			var r = list.Count;
			while (r - l > 1)
			{
				var m = (r + l) / 2;
				if (list[m] >= value)
					r = m;
				else
					l = m;
			}

			return r;
		}

		public static Dictionary<long, long> mp = new Dictionary<long, long>();
		public static long Go(long u, long v, long w)
		{
			long ans = 0;
			while (u != v)
				if (u > v)
				{
					if (!mp.ContainsKey(u))
						mp.Add(u, 0);
					ans += mp[u];
					mp[u] += w;
					u /= 2;
				}
				else
				{
					if (!mp.ContainsKey(v))
						mp.Add(v, 0);
					ans += mp[v];
					mp[v] += w;
					v /= 2;
				}
			return ans;
		}

		public static int GetAns(int x, int pow)
		{
			if (pow == 0)
				return 1;
			if (pow % 2 == 1)
				return (GetAns(x, pow - 1) * 8) % 10;
			var t = GetAns(x, pow / 2);
			return (t * t) % 10;
		}

		public static int ans = 0;
		public static int move = 0;
		public static bool good = false;
		public static int[] x = { 0, 0, 0 };

		public static void solve(int a, int b, int c, int n)
		{
			if (ans != 0)
				return;
			if (n > 0)
			{
				solve(a, c, b, n - 1);
				move++;
				x[a]--;
				x[b]++;
				if (x[a] == x[b] && x[b] == x[c] && ans == 0)
				{
					ans = move;
				}
				solve(c, b, a, n - 1);
			}
		}

		private static void Main()
		{
/*			var input = new StreamReader("input.txt");
			var output = new StreamWriter("output.txt");*/
			var l = ReadListOfLongs();
			var n = l[0];
			var k = l[1];
			var dividers = new List<long>();
			for (var i = 1; (long)i * i <= n; ++i)
			{
				if (n % i == 0)
				{
					dividers.Add(i);
					if ((long)i * i != n)
						dividers.Add(n / i);
				}
			}
			dividers.Sort();
			if (dividers.Count < k)
				Console.WriteLine(-1);
			else
			{
				Console.WriteLine(dividers[(int)k - 1]);
			}
			Console.ReadLine();
			/*			input.Close();
			output.Close();*/
		}
	}
}

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

class Program
{
    private static List<long> GetAllDivisors(long x)
    {
        var div = GetDivisors(x);
        var answer = new List<long>();
        Iterate(1, div, 0, answer, false);

        answer.Sort();

        return answer;
    }

    private static void Iterate(long v, List<Divisor> div, int pos, List<long> answer, bool skip)
    {
        if (!skip)
            answer.Add(v);

        if (pos == div.Count) return;

        Iterate(v, div, pos + 1, answer, true);

        long vv = v;
        for (int j = 0; j < div[pos].K; j++)
        {
            vv *= div[pos].P;
            Iterate(vv, div, pos + 1, answer, false);
        }
    }

    public class Divisor
    {
        public long P;
        public int K;
    }
    private static List<Divisor> GetDivisors(long x)
    {
        int end = (int)Math.Sqrt(x);
        List<Divisor> ans = new List<Divisor>();

        for (int i = 2; i <= end; i++)
            if (x % i == 0)
            {
                var newDiv = new Divisor() { P = i };
                while (x % i == 0)
                {
                    newDiv.K++;
                    x /= i;
                }

                ans.Add(newDiv);
                if (x == 1) break;
            }

        if (x > 1) ans.Add(new Divisor() { P = x, K = 1 });

        return ans;
    }

    private static void SolveA()
    {
        long n = RL();
        int k = RI();

        var divs = GetAllDivisors(n);
        if (k > divs.Count)
            Console.WriteLine(-1);
        else
            Console.WriteLine(divs[k - 1]);
    }

    private static void SolveB()
    {
        var n = RI();
        long ans = 0;
        for (int i = 0; i < n; i++)
        {

        }

        Console.WriteLine(ans);
    }

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

    private const int Mod = 1000000000 + 7;

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

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

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

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

        return g;
    }

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

        return matrix;
    }

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        return s.ToArray();
    }

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

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

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

        return s;
    }

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

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

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

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

        return s.ToArray();
    }

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

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

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

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

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

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

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

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

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

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

using System;
using System.Collections.Generic;
using System.Linq;
using 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.Runtime.InteropServices;

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

             string[] input = Console.ReadLine().Split(" ");

            long res = FindDivisor(Convert.ToInt64(input[0]), Convert.ToInt64(input[1]));
            Console.WriteLine(res);

    }

        static long FindDivisor(long x , long y)
        {
            List<long> a = new List<long>();

            long upperBound = ((long)Math.Sqrt(x));

            if (x != 1)
            {

                for (long i = 1; i <= upperBound; i++)
                {
                    if (x % i == 0)
                    {
                        long first = i;
                        long second = (long) x / i;

                        a.Add(i);
                        if (first != second) {
                            a.Add(x / i);

                        }

                    }
                }
            }
            else {
                a.Add(1);
            }

            try
            {
                a.Sort();
                int z = (int) y;
                return a[z-1];
            }
            catch (ArgumentOutOfRangeException)
            {

                return -1;
            }

        }

    }
}

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

namespace A
{
    class Program
    {
        static void Main(string[] args)
        {
#if !ONLINE_JUDGE
            Console.SetIn(new System.IO.StreamReader(@"..\..\..\in"));
            Console.SetOut(new System.IO.StreamWriter(@"..\..\..\out"));
            for (int testN = 0; testN < 1; testN++)
            {
#endif
                var n = NextLong();
                var k = NextLong();
                var n2 = Math.Sqrt(n);
                var l = new List<long>();

                long c = 0;
                long r = 0;
                long rem = 0;

                while (k > 0 && (c + 1) <= n2)
                {
                    c++;
                    r = Math.DivRem(n, c, out rem);
                    if (rem == 0)
                    {
                        k--;
                        if (r != c)
                        {
                            l.Add(r);
                        }
                    }
                }

                if (k == 0)
                {
                    Console.WriteLine(c);
                }
                else if (l.Count >= k)
                {
                    Console.WriteLine(l[l.Count - (int)k]);
                }
                else
                {
                    Console.WriteLine(-1);
                }

                //Console.WriteLine(string.Format(NumberFormatInfo.InvariantInfo, "{0:F4}", res));
#if !ONLINE_JUDGE
                Console.ReadLine();
            }
            Console.In.Close();
            Console.Out.Close();
#endif
        }

        private static char[] _defaultSplitter = new char[] { ' ', '\t' };

        private static char[] ReadChars(int n)
        {
            char[] buffer = new char[n];
            Console.In.ReadBlock(buffer, 0, n);
            return buffer;
        }

        private static string[] ReadAll()
        {
            return Console.In.ReadToEnd().Split(new char[] { ' ', '\t', '\n', '\r' }, StringSplitOptions.RemoveEmptyEntries);
        }

        private static string[] ReadWords(char[] splitter)
        {
            return Console.ReadLine().Split(splitter, StringSplitOptions.RemoveEmptyEntries);
        }

        private static string[] ReadWords()
        {
            return ReadWords(_defaultSplitter);
        }

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

        private static int[] ReadInts(char[] splitter)
        {
            return Console.ReadLine().Split(splitter, StringSplitOptions.RemoveEmptyEntries).Select(x => int.Parse(x)).ToArray();
        }

        private static int[] ReadInts()
        {
            return ReadInts(_defaultSplitter);
        }

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

        private static long[] ReadLongs(char[] splitter)
        {
            return Console.ReadLine().Split(splitter, StringSplitOptions.RemoveEmptyEntries).Select(x => long.Parse(x)).ToArray();
        }

        private static long[] ReadLongs()
        {
            return ReadLongs(_defaultSplitter);
        }

        private static double ReadDouble()
        {
            return double.Parse(Console.ReadLine(), NumberFormatInfo.InvariantInfo);
        }

        private static int _pos = 0;
        private static string[] _inputLine = new string[0];

        private static void CheckInputLine()
        {
            if (_pos >= _inputLine.Length)
            {
                _inputLine = ReadWords();
                _pos = 0;
            }
        }

        private static string NextWord()
        {
            CheckInputLine();
            return _inputLine[_pos++];
        }

        private static int NextInt()
        {
            CheckInputLine();
            return int.Parse(_inputLine[_pos++]);
        }

        private static long NextLong()
        {
            CheckInputLine();
            return long.Parse(_inputLine[_pos++]);
        }
    }
}

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

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

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

            var divisors = new SortedSet<long>();

            for (int i = 1; i <= n / i; i++)
            {
                if (n % i == 0)
                {
                    divisors.Add(i);
                    divisors.Add(n / i);
                }
            }

            Console.WriteLine(divisors.Skip(k - 1).DefaultIfEmpty(-1).First());
        }
    }
}

using System;
using System.Collections.Generic;

public class Solution
{
    static void Main(string[] args)
    {
        string[] input = Console.ReadLine().Split(' ');
        long n = long.Parse(input[0]);
        long k = long.Parse(input[1]);
        List<long> factors = new List<long>();
        for (long i = 1; i * i <= n; i++)
        {
            if (n % i == 0)
            {
                factors.Add(i);
                long j = n / i;
                if (j > i)
                {
                    factors.Add(j);
                }
            }
        }
        factors.Sort();
        if (factors.Count < k)
        {
            Console.WriteLine(-1);
        }
        else
        {
            Console.WriteLine(factors[(int)k - 1]);
        }
    }
}

using System;
using System.Collections.Generic;

namespace EdxCourse
{
    class Program
    {
        static void Main()
        {
            string[] input = Console.ReadLine().Split(' ');
            ulong n = ulong.Parse(input[0]);
            ulong k = ulong.Parse(input[1]);
            ulong sqrt = Convert.ToUInt64(Math.Sqrt(n)) + 1;
            List<ulong> numbers = new List<ulong>();
            for (ulong i = 1; i < sqrt; i++)
                if (n % i == 0)
                {
                    numbers.Add(i);
                    if (n / i != i)
                        numbers.Add(n / i);
                }
            numbers.Sort();

            ulong len = (ulong)numbers.Count;

            if (k > len)
                Console.WriteLine(-1);
            else
            {
                k--;
                Console.WriteLine(numbers[Convert.ToInt32(k)]);
            }
        }
    }
}

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

class Solver
{
    public void Solve(Scanner sc)
    {
        long N;int K;
        sc.Make(out N, out K);
        var res = new List<long>();
        for(var i=1L;i*i<=N;i++)
            if (N % i == 0)
            {
                res.Add(i);
                if (N / i != i) res.Add(N / i);
            }
        res.Sort();
        if (res.Count < K) Fail(-1);
        WriteLine(res[--K]);
    }
}

#region Template
public static class Template
{
    static void Main(string[] args)
    {
        Console.SetOut(new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false });
        new Solver().Solve(new Scanner());
        Console.Out.Flush();
    }
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public static bool chmin<T>(ref T a, T b) where T : IComparable<T> { if (a.CompareTo(b) == 1) { a = b; return true; } return false; }
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public static bool chmax<T>(ref T a, T b) where T : IComparable<T> { if (a.CompareTo(b) == -1) { a = b; return true; } return false; }
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public static void swap<T>(ref T a, ref T b) { var t = b; b = a; a = t; }
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public static T[] Create<T>(int n, Func<T> f) { var rt = new T[n]; for (var i = 0; i < rt.Length; ++i) rt[i] = f(); return rt; }
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public static T[] Create<T>(int n, Func<int, T> f) { var rt = new T[n]; for (var i = 0; i < rt.Length; ++i) rt[i] = f(i); return rt; }
    public static void Fail<T>(T s) { Console.WriteLine(s); Console.Out.Close(); Environment.Exit(0); }
}

public class Scanner
{
    public string Str => Console.ReadLine().Trim();
    public int Int => int.Parse(Str);
    public long Long => long.Parse(Str);
    public double Double => double.Parse(Str);
    public int[] ArrInt => Str.Split(' ').Select(int.Parse).ToArray();
    public long[] ArrLong => Str.Split(' ').Select(long.Parse).ToArray();
    public char[][] Grid(int n) => Create(n, () => Str.ToCharArray());
    public int[] ArrInt1D(int n) => Create(n, () => Int);
    public long[] ArrLong1D(int n) => Create(n, () => Long);
    public int[][] ArrInt2D(int n) => Create(n, () => ArrInt);
    public long[][] ArrLong2D(int n) => Create(n, () => ArrLong);
    private Queue<string> q = new Queue<string>();
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public T Next<T>() { if (q.Count == 0) foreach (var item in Str.Split(' ')) q.Enqueue(item); return (T)Convert.ChangeType(q.Dequeue(), typeof(T)); }
    public void Make<T1>(out T1 v1) => v1 = Next<T1>();
    public void Make<T1, T2>(out T1 v1, out T2 v2) { v1 = Next<T1>(); v2 = Next<T2>(); }
    public void Make<T1, T2, T3>(out T1 v1, out T2 v2, out T3 v3) { Make(out v1, out v2); v3 = Next<T3>(); }
    public void Make<T1, T2, T3, T4>(out T1 v1, out T2 v2, out T3 v3, out T4 v4) { Make(out v1, out v2, out v3); v4 = Next<T4>(); }
    public void Make<T1, T2, T3, T4, T5>(out T1 v1, out T2 v2, out T3 v3, out T4 v4, out T5 v5) { Make(out v1, out v2, out v3, out v4); v5 = Next<T5>(); }
    public void Make<T1, T2, T3, T4, T5, T6>(out T1 v1, out T2 v2, out T3 v3, out T4 v4, out T5 v5, out T6 v6) { Make(out v1, out v2, out v3, out v4, out v5); v6 = Next<T6>(); }
    //public (T1, T2) Make<T1, T2>() { Make(out T1 v1, out T2 v2); return (v1, v2); }
    //public (T1, T2, T3) Make<T1, T2, T3>() { Make(out T1 v1, out T2 v2, out T3 v3); return (v1, v2, v3); }
    //public (T1, T2, T3, T4) Make<T1, T2, T3, T4>() { Make(out T1 v1, out T2 v2, out T3 v3, out T4 v4); return (v1, v2, v3, v4); }
}
public class Pair<T1, T2> : IComparable<Pair<T1, T2>>
{
    public T1 v1;
    public T2 v2;
    public Pair() { }
    public Pair(T1 v1, T2 v2)
    { this.v1 = v1; this.v2 = v2; }

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

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

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

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

/* Input Methoden :
 *
 * Integer: int n = int.Parse(Console.ReadLine());
 * String:  String n = Console.ReadLine();
 * Integer Array: int[] input = Console.ReadLine().Split(' ').Select(r => Convert.ToInt32(r)).ToArray();
 * String Array:  String[] input = Console.ReadLine().Split(' ');
 *
 * --- Datenstrukturen:
 *   List<Int16> list = new List<Int16>();
 *   HashSet<int> hset = new HashSet<int>();
 *         Dictionary<int, int> dict = new Dictionary<int, int>();
 *
 *
 * Ausgabe: Console.WriteLine();
 *
 *
 *
 */

public class Program
{

    static void Main(String[] args)
    {
        long[] input = Console.ReadLine().Split(' ').Select(r => Convert.ToInt64(r)).ToArray();
        long n = input[0];
        long k = input[1];

        long maxDivisor = (int) Math.Sqrt(n);
        List <long> divisorsLow = new List<long>();
        List<long> divisorsHigh = new List<long>();

        for (int i = 1; i <= maxDivisor; i++) {

           if (n % i == 0) {

                long a = i;
                long b = n / i;

                if (a != b)
                {
                    divisorsLow.Add(a);
                    divisorsHigh.Add(b);
                }
                else {

                    divisorsLow.Add(a);
                }

           }

        }

        if (divisorsLow.Count + divisorsHigh.Count < k)
        {
            Console.WriteLine(-1);

        }
        else {

            if (k <= divisorsLow.Count)
            {
                Console.WriteLine(divisorsLow[(int)k-1]);
            }
            else {

                long dif = k - divisorsLow.Count;
                long ind = divisorsHigh.Count - (dif);

                Console.WriteLine(divisorsHigh[(int)ind]);

                    }

        }

        Console.ReadLine();
    }

}

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

namespace KingsWay
{
    class Program
    {

        static void Main(string[] args)
        {
            string[] token = Console.ReadLine().Split();
            long n = long.Parse(token[0]);
            long k = long.Parse(token[1]);

            long num = n;
            List<long> myList = new List<long>();
           // myList.Contains(i)
            long maxCount =(long) Math.Sqrt(n);
            for(int i=1; ;i++)
            {
                if(i>maxCount)
                     break;
                if(n%i==0)
                {
                     if(!myList.Contains(i))
                     myList.Add(i);
                     num =n / i;
                     if(!myList.Contains(num))
                     myList.Add(num);
                }

            }
            myList.Sort();
            long count = -1;
           //myList.Add(13);
            for(int i = 0;i<myList.Count;i++)
            {
                if(i==k-1)
                {
                    count = myList[i];
                    break;
                }
              // Console.WriteLine(myList[i]);
            }

            if(myList.Count<=1)
               count = 1;
             if(k>n)
             {
                 count = -1;
             }
            Console.WriteLine(count);

        }
    }
}

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

namespace KingsWay
{
    class Program
    {

        static void Main(string[] args)
        {
            string[] token = Console.ReadLine().Split();
            long n = long.Parse(token[0]);
            long k = long.Parse(token[1]);

            long num = n;
            List<long> myList = new List<long>();
           // myList.Contains(i)
            long maxCount =(long) Math.Sqrt(n);
            for(int i=1; ;i++)
            {
                if(i>=num||i>maxCount)
                     break;
                if(n%i==0)
                {
                     if(!myList.Contains(i))
                     myList.Add(i);
                     num =n / i;
                     if(!myList.Contains(num))
                     myList.Add(num);
                }

            }
            myList.Sort();
            long count = -1;
           //myList.Add(13);
            for(int i = 0;i<myList.Count;i++)
            {
                if(i==k-1)
                {
                    count = myList[i];
                    break;
                }
              // Console.WriteLine(myList[i]);
            }

            if(myList.Count<=1)
               count = 1;
             if(k>n)
             {
                 count = -1;
             }
            Console.WriteLine(count);

        }
    }
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Xml.Xsl;
using StringBuilder = System.Text.StringBuilder;

namespace Codeforces
{
	class Program
	{
		static void Main(string[] args)
		{
			string input1 = Console.ReadLine();
			//string input2 = Console.ReadLine();

			//string input3 = Console.ReadLine();
			//string input4 = Console.ReadLine();

			var inputs1 = input1.Split(new[] {' ', '}', '{', ','}, StringSplitOptions.RemoveEmptyEntries).Select(long.Parse).ToArray();
			//var inputs2 = input2.Split(new[] { ' ', '}', '{', ',' }, StringSplitOptions.RemoveEmptyEntries).Select(int.Parse).ToArray();
			//var inputs3 = input3.Split(new[] { ' ', '}', '{', ',' }, StringSplitOptions.RemoveEmptyEntries).Select(long.Parse).ToArray();
			//var inputs4 = input4.Split(new[] { ' ', '}', '{', ',' }, StringSplitOptions.RemoveEmptyEntries).Select(long.Parse).ToArray();

			long n = inputs1[0];
			long k = inputs1[1];

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

			if (n == 1)
			{
				Console.WriteLine(-1);
				return;
			}

			long copyN = n;
			long border = n / 2;
			var ds = new List<long>{ 1 };
			int index = 1;
			for (long i = 2; i <= border; i++)
			{
				if (i > Math.Sqrt(n))
				{
					break;
				}

				if (copyN % i > 0)
				{
					continue;
				}

				if (copyN / i != i)
				{
					ds.Insert(index, n / i);
				}

				ds.Insert(index++, i);
				border = n / i;
				if (index > k)
				{
					break;
				}
			}

			ds.Add(n);
			if (ds.Count >= k)
			{
				Console.WriteLine(ds.ElementAt((int)(k - 1)));
			}
			else
			{
				Console.WriteLine(-1);
			}
		}

		public class Team
		{
			public string Name { get; set; }

			public int Points { get; set; }

			public int GoalsFor { get; set; }

			public int GoalsAgainst { get; set; }
		}

		static long Factorial(long a)
		{
			return a > 1 ? a * Factorial(a - 1) : 1;
		}
	}
}

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)
        {
            var data = Console.ReadLine().Split().Select(long.Parse).ToArray();
            var cnt = 0;
            var n = data[0];
            var k = data[1];
            var sqrN = (long)Math.Sqrt(n);
            var d = 1;
            var firstDivs = new List<long>();
            var secondDivs = new List<long>();
            while (d <=sqrN)
            {
                if (n%d == 0)
                {
                    firstDivs.Add(d);
                    if(n/d != d)
                        secondDivs.Add(n/d);
                }
                d++;
            }
            if(k > firstDivs.Count + secondDivs.Count)
                Console.WriteLine(-1);
            if (k > firstDivs.Count)
            {
                k -= firstDivs.Count;
                for (int i = secondDivs.Count-1; i > -1; i--)
                {
                    if (k == 1)
                    {
                        Console.WriteLine(secondDivs[i]);
                        return;
                    }

                    k--;

                }
            }
            else
            {
                for (int i = 0; i < firstDivs.Count; i++)
                {
                    if (k == 1)
                    {
                        Console.WriteLine(firstDivs[i]);
                        return;
                    }
                    k--;
                }
            }
        }
    }
}

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

namespace Olymp
{
  public class ProblemSolver
  {
    private Tokenizer input;

    public void Solve()
    {
      long n = input.NextLong();
      int k = input.NextInt();
      long last = (long)Math.Sqrt(n);
      int c = 0;
      for (long i = 1; i <= last; i++)
      {
        if (n % i == 0)
        {
          c++;
          if (c == k)
          {
            Console.Write(i);
            return;
          }
        }
      }
      if (last * last == n)
      {
        last--;
        c--;
      }
      for (long i = last; i > 0; i--)
      {
        if (n % i == 0)
        {
          c++;
          if (c == k)
          {
            Console.Write(n / i);
            return;
          }
        }
      }
      Console.Write(-1);
    }

    public ProblemSolver(TextReader input)
    {
      this.input = new Tokenizer(input);
    }
  }

  #region Service classes

  public class Tokenizer
  {
    private TextReader reader;

    public int NextInt()
    {
      var c = SkipWS();
      if (c == -1)
        throw new EndOfStreamException();
      bool isNegative = false;
      if (c == '-' || c == '+')
      {
        isNegative = c == '-';
        c = this.reader.Read();
        if (c == -1)
          throw new InvalidOperationException();
      }
      if (!char.IsDigit((char)c))
        throw new InvalidOperationException();
      int result = (char)c - '0';
      c = this.reader.Read();
      while (c > 0 && !char.IsWhiteSpace((char)c))
      {
        if (!char.IsDigit((char)c))
          throw new InvalidOperationException();
        result = result * 10 + (char)c - '0';
        c = this.reader.Read();
      }
      if (isNegative)
        result = -result;
      return result;
    }

    public string ReadLine()
    {
      return reader.ReadLine();
    }

    public long NextLong()
    {
      return long.Parse(this.NextToken());
    }

    public double NextDouble()
    {
      return double.Parse(this.NextToken(), CultureInfo.InvariantCulture);
    }

    public int[] ReadIntArray(int n)
    {
      int[] a = new int[n];
      for (int i = 0; i < n; i++)
        a[i] = NextInt();
      return a;
    }

    public long[] ReadLongArray(int n)
    {
      long[] a = new long[n];
      for (int i = 0; i < n; i++)
        a[i] = NextLong();
      return a;
    }

    public double[] ReadDoubleArray(int n)
    {
      double[] a = new double[n];
      for (int i = 0; i < n; i++)
        a[i] = NextDouble();
      return a;
    }

    public string NextToken()
    {
      var c = SkipWS();
      if (c == -1)
        return null;
      var sb = new StringBuilder();
      while (c > 0 && !char.IsWhiteSpace((char)c))
      {
        sb.Append((char)c);
        c = this.reader.Read();
      }
      return sb.ToString();
    }

    private int SkipWS()
    {
      int c = this.reader.Read();
      if (c == -1)
        return c;
      while (c > 0 && char.IsWhiteSpace((char)c))
        c = this.reader.Read();
      return c;
    }

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

  class Program
  {
    public static void Main(string[] args)
    {
      var solver = new ProblemSolver(Console.In);
      solver.Solve();
    }
  }

  #endregion
}

using System;
using System.Collections.Generic;

public class Program
{
    static void Main(string[] args)
    {
        string[] ip = Console.ReadLine().Split();
        long n = long.Parse(ip[0]);
        int k = int.Parse(ip[1]);
        var lower = new List<long>();
        var higher = new List<long>();
        long i;
        for(i = 1; i * i < n; i++)
        {
            if(n % i == 0)
            {
                lower.Add(i);
                higher.Add(n / i);
            }
        }
        if(i * i == n)
        {
            lower.Add(i);
        }
        long ans;
        if(k <= lower.Count)
        {
            ans = lower[k - 1];
        }
        else if(k <= lower.Count + higher.Count)
        {
            ans = higher[k - lower.Count - 1];
        }
        else
        {
            ans = -1;
        }
        Console.WriteLine(ans);
    }
}

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+1; 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 ааа
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] num = Console.ReadLine().Split(' ');
            Int64 n = Int64.Parse(num[0]);
            Int64 k = Int64.Parse(num[1]);
           Int64 End =Convert.ToInt64(Math.Sqrt(n));
           Int16 count = 0;
           bool fl = true;
          // List<Int64> spisok = new List<Int64>();
           for (int i = 1; i <= End+1; i++)
           {
               if (n%i==0)
               {
                   count++;
                   if (count==k)
                   {
                       fl = false;
                       Console.WriteLine(i);
                       break;
                   }
               }
           }
           if (fl==true&&(k-count==1))
           {
               fl = false;
               Console.WriteLine(n);
           }
           if (fl)
           {
               Console.WriteLine(-1);
           }
          // Console.ReadKey();
        }
    }
}

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]);
            Int64 k = Int64.Parse(num[1]);
           Int64 End =Convert.ToInt64(Math.Sqrt(n));
           End = End * 2;
           Int16 count = 0;
           bool fl = true;
          // List<Int64> spisok = new List<Int64>();
           for (int i = 1; i <= End+1; i++)
           {
               if (n%i==0)
               {
                   count++;
                   if (count==k)
                   {
                       fl = false;
                       Console.WriteLine(i);
                       break;
                   }
               }
           }
           if (fl==true&&(k-count==1))
           {
               fl = false;
               Console.WriteLine(n);
           }
           if (fl)
           {
               Console.WriteLine(-1);
           }
           //Console.ReadKey();
        }
    }
}

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

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

				//Console.ReadKey();
			}
		}
	}

	internal class Task
	{
		public void Solve(InputReader sr, TextWriter sw)
		{
			var input = sr.ReadArray(Int64.Parse);
			var n = input[0];
			var k = input[1];
			var mid = (long)Math.Sqrt(n);
			var div1 = new List<long>();
			var div2 = new List<long>();
			for (var i = 1; i <= mid; i++) {
				if (n % i == 0) {
					div1.Add(i);
					div2.Add(n / i);
				}
			}
			if (div1.Count + div2.Count < k) {
				sw.WriteLine(-1);
				return;
			}
			if (div1.Count >= k) {
				sw.WriteLine(div1[(int)k - 1]);
				return;
			}

			sw.WriteLine(div2[div2.Count - ((int) k -div1.Count)]);
		}
	}
}

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

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

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

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

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

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

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

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

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

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

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

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

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

				//Console.ReadKey();
			}
		}
	}

	internal class Task
	{
		public void Solve(InputReader sr, TextWriter sw)
		{
			var input = sr.ReadArray(Int64.Parse);
			var n = input[0];
			var k = input[1];
			var mid = (long)Math.Sqrt(n);
			var curr = 0;
			for (var i = 1; i <= mid; i++) {
				if (n % i == 0) {
					curr++;
				}
				if (curr == k) {
					sw.WriteLine(i);
					return;
				}
			}

			sw.WriteLine(-1);
		}
	}
}

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

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

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

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

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

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

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

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

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

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

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

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

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

				//Console.ReadKey();
			}
		}
	}

	internal class Task
	{
		public void Solve(InputReader sr, TextWriter sw)
		{
			var input = sr.ReadArray(Int64.Parse);
			var n = input[0];
			var k = input[1];
			var div1 = new List<long>();
			var div2 = new List<long>();
			for (var i = 1L; i * i <= n; i++) {
				if (n % i == 0) {
					div1.Add(i);
					div2.Add(n / i);
				}
			}
			if (div1.Count + div2.Count < k) {
				sw.WriteLine(-1);
				return;
			}
			if (div1.Count >= k) {
				sw.WriteLine(div1[(int)k - 1]);
				return;
			}

			sw.WriteLine(div2[div2.Count - ((int) k -div1.Count)]);
		}
	}
}

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

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

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

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

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

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

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

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

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

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

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

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

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

				//Console.ReadKey();
			}
		}
	}

	internal class Task
	{
		public void Solve(InputReader sr, TextWriter sw)
		{
			var input = sr.ReadArray(Int64.Parse);
			var n = input[0];
			var k = input[1];
			var mid = (long)Math.Sqrt(n);
			var div1 = new List<long>();
			var div2 = new List<long>();
			for (var i = 1; i <= mid; i++) {
				if (n % i == 0) {
					div1.Add(i);
					div2.Add(n / i);
				}
			}
			if (div1.Count + div2.Count < k) {
				sw.WriteLine(-1);
				return;
			}
			if (div1.Count >= k) {
				sw.WriteLine(div1[(int)k - 1]);
				return;
			}

			sw.WriteLine(div2[((int) k -div1.Count - 1)]);
		}
	}
}

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

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

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

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

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

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

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

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

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

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

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

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

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

				//Console.ReadKey();
			}
		}
	}

	internal class Task
	{
		public void Solve(InputReader sr, TextWriter sw)
		{
			var input = sr.ReadArray(Int64.Parse);
			var n = input[0];
			var k = input[1];
			var mid = (long)Math.Sqrt(n);
			var div1 = new List<long>();
			var div2 = new List<long>();
			for (var i = 1; i <= mid; i++) {
				if (n % i == 0) {
					div1.Add(i);
					div2.Add(n / i);
				}
			}
			if (div1.Count + div2.Count < k) {
				sw.WriteLine(-1);
				return;
			}
			if (div1.Count >= k) {
				sw.WriteLine(div1[(int)k - 1]);
				return;
			}

			sw.WriteLine(div2[div2.Count - ((int) k -div1.Count - 1) - 1]);
		}
	}
}

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

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

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

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

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

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

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

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

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

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

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

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

namespace A_kth_divisor
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] input = Console.ReadLine().Split(' ');
            long n = long.Parse(input[0]);
            long k = long.Parse(input[1]);
            bool b = false;

            long sqrt = (long)(Math.Ceiling(Math.Sqrt(n)));
            if (sqrt * sqrt == n)  b = true;

            long[] divs = new long[100000];
            long[] mirror = new long[100000];
            long counter = 0;
            for (long i = 1; i < sqrt; i++)
            {
                if (n % i == 0)
                {
                    divs[counter] = i;
                    mirror[counter] = n / i;
                    counter++;
                }
            }

            if (k > (counter) * 2 + Convert.ToInt64(b)) Console.WriteLine("-1");
            else if (k <= counter) Console.WriteLine(divs[k-1]);
            else if (b) Console.WriteLine(sqrt);
            else Console.WriteLine(mirror[(counter) * 2 + Convert.ToInt64(b) - k]);
        }
    }
}

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

namespace A_kth_divisor
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] input = Console.ReadLine().Split(' ');
            long n = long.Parse(input[0]);
            long k = long.Parse(input[1]);
            bool b = false;

            long sqrt = (long)(Math.Ceiling(Math.Sqrt(n)));
            if (sqrt * sqrt == n)  b = true;

            long[] divs = new long[100000];
            long[] mirror = new long[100000];
            long counter = 0;
            for (long i = 1; i < sqrt; i++)
            {
                if (n % i == 0)
                {
                    divs[counter] = i;
                    mirror[counter] = n / i;
                    counter++;
                }
            }

            if (k > (counter) * 2 + Convert.ToInt64(b)) Console.WriteLine("-1");
            else if (k <= counter) Console.WriteLine(divs[k]);
            else if (b) Console.WriteLine(sqrt);
            else Console.WriteLine(mirror[(counter) * 2 + Convert.ToInt64(b) - k]);
        }
    }
}

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

namespace A_kth_divisor
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] input = Console.ReadLine().Split(' ');
            long n = long.Parse(input[0]);
            long k = long.Parse(input[1]);
            bool b = false;

            int sqrt = (int)(Math.Ceiling(Math.Sqrt(n)));
            if (sqrt * sqrt == n)  b = true;

            long[] divs = new long[100000];
            long[] mirror = new long[100000];
            int counter = 0;
            for (int i = 1; i < sqrt; i++)
            {
                if (n % i == 0)
                {
                    divs[counter] = i;
                    mirror[counter] = (long)n / i;
                    counter++;
                }
            }

            if (k > (counter) * 2 + Convert.ToInt32(b)) Console.WriteLine("-1");
            else if (k <= counter) Console.WriteLine(divs[k]);
            else if (b) Console.WriteLine(sqrt);
            else Console.WriteLine(mirror[(counter) * 2 + Convert.ToInt64(b) - k]);
        }
    }
}

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

namespace A_kth_divisor
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] input = Console.ReadLine().Split(' ');
            long n = long.Parse(input[0]);
            long k = long.Parse(input[1]);

            //int sqrt = (int)Math.Sqrt(n);
            int counter = 0;
            for (int i = 1; i < n; i++)
            {
                if (n % i == 0)
                {
                    counter++;
                    if (counter == k) { Console.WriteLine(i); break; }
                }
                else if (counter > k) { Console.WriteLine("-1"); break; }

            }

            if (counter < k) Console.WriteLine("-1");
        }
    }
}

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

namespace A_kth_divisor
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] input = Console.ReadLine().Split(' ');
            long n = long.Parse(input[0]);
            long k = long.Parse(input[1]);
            bool b = false;

            int sqrt = (int)(Math.Ceiling(Math.Sqrt(n)));
            if (sqrt * sqrt == n)  b = true;

            int[] divs = new int[100000];
            int[] mirror = new int[100000];
            int counter = 0;
            for (int i = 1; i < sqrt; i++)
            {
                if (n % i == 0)
                {
                    divs[counter] = i;
                    mirror[counter] = (int)n / i;
                    counter++;
                }
            }

            if (k > (counter) * 2 + Convert.ToInt32(b)) Console.WriteLine("-1");
            else if (k <= counter) Console.WriteLine(divs[k]);
            else if (b) Console.WriteLine(sqrt);
            else Console.WriteLine(mirror[(counter) * 2 + Convert.ToInt32(b) - k]);
        }
    }
}

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

namespace A_kth_divisor
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] input = Console.ReadLine().Split(' ');
            long n = long.Parse(input[0]);
            long k = long.Parse(input[1]);
            bool b = false;

            long sqrt = (long)(Math.Ceiling(Math.Sqrt(n)));
            if (sqrt * sqrt == n)  b = true;

            long[] divs = new long[100000];
            long[] mirror = new long[100000];
            int counter = 0;
            for (int i = 1; i < sqrt; i++)
            {
                if (n % i == 0)
                {
                    divs[counter] = i;
                    mirror[counter] = (long)n / i;
                    counter++;
                }
            }

            if (k > (counter) * 2 + Convert.ToInt64(b)) Console.WriteLine("-1");
            else if (k <= counter) Console.WriteLine(divs[k]);
            else if (b) Console.WriteLine(sqrt);
            else Console.WriteLine(mirror[(counter) * 2 + Convert.ToInt64(b) - k]);
        }
    }
}

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

namespace k_divisor
{
    class Program
    {
        static long max = 31622780;
        static long[] primes = new long[max];
        static List<long> facts = new List<long>();
        static List<long> factoring = new List<long>();
        static List<long> divisors = new List<long>();
        static void Cieve()
        {
            for (long i = 4; i < max; i += 2) primes[i] = 2;
            for (long i = 3; i * i < max; i += 2)
                if (primes[i] == -1)
                    for (long j = i * i; j < max; j += 2 * i)
                        primes[j] = i;
        }

        static void prime_fact(long n)
        {
            for (long i = 2; i < max; i++)
            {
                if (primes[i] == -1 && n % i == 0)
                    facts.Add(i);
            }
        }

        static void factorization(long n)
        {
            long aux = n;
            for (int i = 0; i < facts.Count; i++)
            {
                int c = 0;
                long v = facts[i];
                while (aux % v == 0)
                {
                    c++;
                    aux /= v;
                }
                factoring.Add(v); factoring.Add(c);
            }
            if(aux > 1){
                factoring.Add(aux);
                factoring.Add(1);
            }
        }

        static void Divisors(long n)
        {
            for (int i = 0; i < factoring.Count; i += 2)
            {
                int c = 0;
                long v = factoring[i];
                for (int k = 1; k <= factoring[i+1]; k++)
                {
                    long x = (long)Math.Pow(v, k);
                    if (x < n)
                    {
                        divisors.Add(x);
                        c++;
                    }
                    else
                        break;
                }
                int t = divisors.Count;
                for(int j = t-c; j < t; j++)
                    for(int s = 0; s < t-c; s++){
                        long aux = divisors[j]*divisors[s];
                        if(aux < n)
                            divisors.Add(aux);
                    }
            }
            divisors.Add(n);
            divisors.Insert(0, 1);
            divisors.Sort();
        }
        static void Main(string[] args)
        {
            string s = Console.ReadLine();
            char []sep= new char[]{' '};
            string[] ns = s.Split(sep,2);
            long n = long.Parse(ns[0]);
            long k = long.Parse(ns[1]);
            if(k > 50)
            {
                Console.WriteLine(-1);
                return;
            }
            if (n == 1)
            {
                if(k == 1)
                    Console.WriteLine(1);
                else
                    Console.WriteLine(-1);
                return;
            }
            for (long i = 2; i < max; i++)
            {
                primes[i] = -1;
            }
            Cieve();
            prime_fact(n);
            factorization(n);
            Divisors(n);
            if (k > divisors.Count)
            {
                Console.WriteLine(-1);
                return;
            }
            int t = (int)k;
            Console.WriteLine(divisors[t-1]);
        }
    }
}

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

namespace k_divisor
{
    class Program
    {
        static long max = 31622780;
        static long[] primes = new long[max];
        static List<long> facts = new List<long>();
        static List<long> factoring = new List<long>();
        static List<long> divisors = new List<long>();
        static void Cieve()
        {
            for (long i = 4; i < max; i += 2) primes[i] = 2;
            for (long i = 3; i * i < max; i += 2)
                if (primes[i] == -1)
                    for (long j = i * i; j < max; j += 2 * i)
                        primes[j] = i;
        }

        static void prime_fact(long n)
        {
            for (long i = 2; i < max; i++)
            {
                if (primes[i] == -1 && n % i == 0)
                    facts.Add(i);
            }
        }

        static void factorization(long n)
        {
            long aux = n;
            for (int i = 0; i < facts.Count; i++)
            {
                int c = 0;
                long v = facts[i];
                while (aux % v == 0)
                {
                    c++;
                    aux /= v;
                }
                factoring.Add(v); factoring.Add(c);
            }
			facts.Clear();
            if(aux > 1){
                factoring.Add(aux);
                factoring.Add(1);
            }

        }

        static void Divisors(long n)
        {
            for (int i = 0; i < factoring.Count; i += 2)
            {
                int c = 0;
                long v = factoring[i];
                for (int k = 1; k <= factoring[i+1]; k++)
                {
                    long x = (long)Math.Pow(v, k);
                    if (x < n)
                    {
                        divisors.Add(x);
                        c++;
                    }
                    else
                        break;
                }
				factoring.Clear();
                int t = divisors.Count;
                for(int j = t-c; j < t; j++)
                    for(int s = 0; s < t-c; s++){
                        long aux = divisors[j]*divisors[s];
                        if(aux < n)
                            divisors.Add(aux);
                    }
            }
            divisors.Add(n);
            divisors.Insert(0, 1);
            divisors.Sort();
        }
        static void Main(string[] args)
        {
            string s = Console.ReadLine();
            char []sep= new char[]{' '};
            string[] ns = s.Split(sep,2);
            long n = long.Parse(ns[0]);
            long k = long.Parse(ns[1]);
            if (n == 1)
            {
                if(k == 1)
                    Console.WriteLine(1);
                else
                    Console.WriteLine(-1);
                return;
            }
            for (long i = 2; i < max; i++)
            {
                primes[i] = -1;
            }
            Cieve();
            prime_fact(n);
            factorization(n);
            Divisors(n);
            if (k > divisors.Count)
            {
                Console.WriteLine(-1);
                return;
            }
            int t = (int)k;
            Console.WriteLine(divisors[t-1]);
        }
    }
}

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

class cf1
{
    static void Main()
    {
        string strInfo01 = Console.ReadLine();

        long lngNumber = long.Parse(strInfo01.Split()[0]);
        long lngPosition = long.Parse(strInfo01.Split()[1]);
        long lngSquare = (long)Math.Sqrt(lngNumber);

        List<long> lstResults = new List<long>();

        for (long i = 1; i <= lngSquare; i++)
        {
            if (lngNumber % i == 0)
            {
                lstResults.Add(i);
                if (i != lngNumber/i)
                {
                    lstResults.Add(lngNumber / i);
                }
            }
        }

        lstResults.Sort();

        if (lstResults.Count< lngPosition+1)
        {
            Console.WriteLine(-1);
        }
        else
        {
            Console.WriteLine(lstResults [(int)lngPosition]);
        }
    }
}

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

namespace denemexxxx
{
    class Program
    {
        static void Main(string[] args)
        {
            try {
                int[] sayilar = new int[10000000];
                int sayac = 0;
                int[] nk = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
                for (int i = 1; i <= nk[0] / 2; i++)
                {
                    if (nk[0] % i == 0)
                    {
                        sayilar[sayac] = i;
                        sayac++;
                    }
                }
                sayilar[sayac] = nk[0];
                if (sayilar[nk[1] - 1] == 0)
                    Console.Write(-1);
                else
                    Console.WriteLine(sayilar[nk[1] - 1]);

                Console.ReadKey();
            }
            catch { }

        }
    }
}

using System;
using System.Collections.Generic;

class Program
{
    static void Main(string[] args)
    {
        string[] inputs = Console.ReadLine().Split(' ');
        Console.WriteLine(Solve(long.Parse(inputs[0]), int.Parse(inputs[1])));
    }

    static long Solve(long n, int k)
    {
        List<int> divisors = new List<int>(5000);

        for (int i = 1; (long)i * i <= n; i++)
        {
            if (n % i == 0)
                divisors.Add(i);
        }

        if (k > (divisors.Count * 2) - (IsPerfectSquare(n) ? 1 : 0))
            return -1;

        int offset = (IsPerfectSquare(n) ? 1 : 0);
        return (k <= divisors.Count) ? divisors[k - 1] : (n / divisors[2 * divisors.Count - k - offset]);
    }

    static bool IsPerfectSquare(long n)
    {
        var sq = (int)Math.Sqrt(n);
        return sq * sq == n;
    }
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;

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

             string[] input = Console.ReadLine().Split(" ");

            long res = FindDivisor(Convert.ToInt64(input[0]), Convert.ToInt64(input[1]));
            Console.WriteLine(res);

    }

        static long FindDivisor(long x , long y)
        {
            List<long> a = new List<long>();

            int upperBound = ((int)Math.Sqrt(x));

            if (x != 1) {

            for (int i = 1; i <= upperBound; i++)
            {
                if (x % i == 0)
                {
                    a.Add(i);
                    a.Add(x / i);
                }
            }
            }

            try
            {
                a.Sort();
                int z = (int) y;
                return a[z-1];
            }
            catch (ArgumentOutOfRangeException)
            {

                return -1;
            }

        }

    }
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;

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

             string[] input = Console.ReadLine().Split(" ");

            long res = FindDivisor(Convert.ToInt64(input[0]), Convert.ToInt64(input[1]));
            Console.WriteLine(res);

    }

        static long FindDivisor(long x , long y)
        {
            List<long> a = new List<long>();

            int upperBound = ((int)Math.Sqrt(x));

            for (int i = 1; i <= upperBound; i++)
            {
                if (x % i == 0)
                {
                    a.Add(i);
                    a.Add(x / i);
                }
            }
            try
            {
                a.Sort();
                int z = (int) y;
                return a[z-1];
            }
            catch (ArgumentOutOfRangeException)
            {

                return -1;
            }

        }

    }
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;

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

             string[] input = Console.ReadLine().Split(" ");

            long res = FindDivisor(Convert.ToInt64(input[0]), Convert.ToInt64(input[1]));
            Console.WriteLine(res);

    }

        static long FindDivisor(long x , long y)
        {
            List<long> a = new List<long>();

            int upperBound = ((int)Math.Sqrt(x));

            if (x != 1)
            {

                for (int i = 1; i <= upperBound; i++)
                {
                    if (x % i == 0)
                    {
                        a.Add(i);
                        a.Add(x / i);
                    }
                }
            }
            else {
                a.Add(1);
            }

            try
            {
                a.Sort();
                int z = (int) y;
                return a[z-1];
            }
            catch (ArgumentOutOfRangeException)
            {

                return -1;
            }

        }

    }
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;

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

             string[] input = Console.ReadLine().Split(" ");

            long res = FindDivisor(Convert.ToInt64(input[0]), Convert.ToInt64(input[1]));
            Console.WriteLine(res);

    }

        static long FindDivisor(long x , long y)
        {
            List<long> a = new List<long>();

            long upperBound = ((long)Math.Sqrt(x));

            if (x != 1)
            {

                for (long i = 1; i <= upperBound; i++)
                {
                    if (x % i == 0)
                    {
                        long first = i;
                        long second = (long) x / i;

                        a.Add(i);
                        Console.WriteLine(first);

                        if (first != second) {
                            a.Add(x / i);
                            Console.WriteLine(second);
                        }

                    }
                }
            }
            else {
                a.Add(1);
            }

            try
            {
                a.Sort();
                int z = (int) y;
                return a[z-1];
            }
            catch (ArgumentOutOfRangeException)
            {

                return -1;
            }

        }

    }
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;

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

             string[] input = Console.ReadLine().Split(" ");

            long res = FindDivisor(Convert.ToInt64(input[0]), Convert.ToInt64(input[1]));
            Console.WriteLine(res);

    }

        static long FindDivisor(long x , long y)
        {
            List<long> a = new List<long>();

            int upperBound = ((int)Math.Sqrt(x));

            if (x != 1)
            {

                for (int i = 1; i <= upperBound; i++)
                {
                    if (x % i == 0)
                    {
                        int first = i;
                        int second = (int) x / i;

                        a.Add(i);

                        if (first != second) {
                            a.Add(x / i);
                        }

                    }
                }
            }
            else {
                a.Add(1);
            }

            try
            {
                a.Sort();
                int z = (int) y;
                return a[z-1];
            }
            catch (ArgumentOutOfRangeException)
            {

                return -1;
            }

        }

    }
}

using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;

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

             string[] input = Console.ReadLine().Split(" ");

            long res = FindDivisor(Convert.ToInt64(input[0]), Convert.ToInt64(input[1]));
            Console.WriteLine(res);

    }

        static long FindDivisor(long x , long y)
        {
            List<long> a = new List<long>();

            int upperBound = ((int)Math.Sqrt(x)) + 1;

            for (int i = 1; i <= upperBound; i++)
            {
                if (x % i == 0)
                {
                    a.Add(i);
                    a.Add(x / i);
                }
            }
            try
            {
                a.Sort();
                int z = (int) y;
                return a[z-1];
            }
            catch (ArgumentOutOfRangeException)
            {

                return -1;
            }

        }

    }
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;

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

             string[] input = Console.ReadLine().Split(" ");

            long res = FindDivisor(Convert.ToInt64(input[0]), Convert.ToInt64(input[1]));
            Console.WriteLine(res);

    }

        static long FindDivisor(long x , long y)
        {
            List<long> a = new List<long>();

            int upperBound = ((int)Math.Sqrt(x));
            Console.WriteLine(upperBound);

            for (int i = 1; i <= upperBound; i++)
            {
                if (x % i == 0)
                {
                    a.Add(i);
                    a.Add(x / i);
                }
            }
            try
            {
                a.Sort();
                int z = (int) y;
                return a[z-1];
            }
            catch (ArgumentOutOfRangeException)
            {

                return -1;
            }

        }

    }
}

using System;

namespace EdxCourse
{
    class Program
    {
        static void Main()
        {
            string[] input = Console.ReadLine().Split(' ');
            long n = long.Parse(input[0]);
            long k = long.Parse(input[1]);
            long sqrt = Convert.ToInt64(Math.Sqrt(n)) + 1;
            long[] numbers = new long[sqrt];
            int len = 0;
            for (long i = 1; i < sqrt; i++)
                if (n % i == 0)
                    numbers[len++] = i;

            if (k > len * 2)
                Console.WriteLine(-1);
            else
            {
                k -= 1;
                if (k >= len)
                    Console.WriteLine(n / numbers[k - len]);
                else
                    Console.WriteLine(numbers[k]);
            }
        }
    }
}

using System;
using System.Collections.Generic;

namespace EdxCourse
{
    class Program
    {
        static void Main()
        {
            string[] input = Console.ReadLine().Split(' ');
            ulong n = ulong.Parse(input[0]);
            ulong k = ulong.Parse(input[1]);
            ulong sqrt = Convert.ToUInt64(Math.Sqrt(n)) + 1;
            List<ulong> numbers = new List<ulong>();
            uint len = 0;
            for (ulong i = 1; i < sqrt; i++)
                if (n % i == 0)
                {
                    numbers.Add(i);
                    numbers.Add(n / i);
                    len += 2;
                }
            numbers.Sort();

            if (k > len)
                Console.WriteLine(-1);
            else
            {
                k--;
                Console.WriteLine(numbers[Convert.ToInt32(k)]);
            }
        }
    }
}

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

namespace KingsWay
{
    class Program
    {

        static void Main(string[] args)
        {
            string[] token = Console.ReadLine().Split();
            long n = long.Parse(token[0]);
            long k = long.Parse(token[1]);

            long num = n;
            List<long> myList = new List<long>();
           // myList.Contains(i)
            for(int i=1; ;i++)
            {
                if(n%i==0)
                {
                    if(i>=num)
                     break;
                     myList.Add(i);
                     num =n / i;
                     myList.Add(num);
                }
            }
            myList.Sort();
            long count = -1;
           //myList.Add(13);
            for(int i = 0;i<myList.Count;i++)
            {
                if(i==k-1)
                {
                    count = myList[i];
                    break;
                }
              // Console.WriteLine(myList[i]);
            }
            if(myList.Count<=1)
               count = 1;
            Console.WriteLine(count);

        }
    }
}

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

namespace KingsWay
{
    class Program
    {

        static void Main(string[] args)
        {
            string[] token = Console.ReadLine().Split();
            long n = long.Parse(token[0]);
            long k = long.Parse(token[1]);

            long num = n;
            List<long> myList = new List<long>();
           // myList.Contains(i)
            for(int i=1; ;i++)
            {
                if(n%i==0)
                {
                    if(i>=num)
                     break;
                     myList.Add(i);
                     num =n / i;
                     myList.Add(num);
                }
            }
            myList.Sort();
            long count = -1;
           //myList.Add(13);
            for(int i = 0;i<myList.Count;i++)
            {
                if(i==k-1)
                {
                    count = myList[i];
                    break;
                }
              // Console.WriteLine(myList[i]);
            }

            if(myList.Count<=1&&k<n)
               count = 1;
            Console.WriteLine(count);

        }
    }
}

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

namespace KingsWay
{
    class Program
    {

        static void Main(string[] args)
        {
            string[] token = Console.ReadLine().Split();
            long n = long.Parse(token[0]);
            long k = long.Parse(token[1]);

            long num = n;
            List<long> myList = new List<long>();
           // myList.Contains(i)
            long h = (n%2==0)?n/2:n+1/2;
            for(int i=1;i<h ;i++)
            {
                if(i>=num)
                     break;
                if(n%i==0)
                {
                     if(!myList.Contains(i))
                     myList.Add(i);
                     num =n / i;
                     if(!myList.Contains(num))
                     myList.Add(num);
                }

            }
            myList.Sort();
            long count = -1;
           //myList.Add(13);
            for(int i = 0;i<myList.Count;i++)
            {
                if(i==k-1)
                {
                    count = myList[i];
                    break;
                }
              // Console.WriteLine(myList[i]);
            }

            if(myList.Count<=1)
               count = 1;
             if(k>n)
             {
                 count = -1;
             }
            Console.WriteLine(count);

        }
    }
}

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

namespace KingsWay
{
    class Program
    {

        static void Main(string[] args)
        {
            string[] token = Console.ReadLine().Split();
            long n = long.Parse(token[0]);
            long k = long.Parse(token[1]);

            long num = n;
            List<long> myList = new List<long>();
           // myList.Contains(i)
            for(int i=1;i<19191 ;i++)
            {
                if(i>=num)
                     break;
                if(n%i==0)
                {
                     if(!myList.Contains(i))
                     myList.Add(i);
                     num =n / i;
                     if(!myList.Contains(num))
                     myList.Add(num);
                }

            }
            myList.Sort();
            long count = -1;
           //myList.Add(13);
            for(int i = 0;i<myList.Count;i++)
            {
                if(i==k-1)
                {
                    count = myList[i];
                    break;
                }
              // Console.WriteLine(myList[i]);
            }

            if(myList.Count<=1)
               count = 1;
             if(k>n)
             {
                 count = -1;
             }
            Console.WriteLine(count);

        }
    }
}

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

namespace KingsWay
{
    class Program
    {

        static void Main(string[] args)
        {
            string[] token = Console.ReadLine().Split();
            long n = long.Parse(token[0]);
            long k = long.Parse(token[1]);

            long num = n;
            List<long> myList = new List<long>();
           // myList.Contains(i)
            for(int i=1; i<30;i++)
            {
                if(n%i==0)
                {
                    if(i>=num)
                     break;
                     myList.Add(i);
                     num =n / i;
                     myList.Add(num);

                }

            }
            myList.Sort();
            long count = -1;
           //myList.Add(13);
            for(int i = 0;i<myList.Count;i++)
            {
                if(i==k-1)
                {
                    count = myList[i];
                    break;
                }
              // Console.WriteLine(myList[i]);
            }

            Console.WriteLine(count);

        }
    }
}

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

namespace KingsWay
{
    class Program
    {

        static void Main(string[] args)
        {
            string[] token = Console.ReadLine().Split();
            long n = long.Parse(token[0]);
            long k = long.Parse(token[1]);

            long num = n;
            List<long> myList = new List<long>();
           // myList.Contains(i)
            for(int i=1; ;i++)
            {
                if(n%i==0)
                {
                    if(i>=num)
                     break;
                     myList.Add(i);
                     num =n / i;
                     myList.Add(num);
                }
            }
            myList.Sort();
            long count = -1;
           //myList.Add(13);
            for(int i = 0;i<myList.Count;i++)
            {
                if(i==k-1)
                {
                    count = myList[i];
                    break;
                }
              // Console.WriteLine(myList[i]);
            }

            if(myList.Count<=1)
               count = 1;
             if(k>n)
             {
                 count = -1;
             }
            Console.WriteLine(count);

        }
    }
}

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

namespace KingsWay
{
    class Program
    {

        static void Main(string[] args)
        {
            string[] token = Console.ReadLine().Split();
            long n = long.Parse(token[0]);
            long k = long.Parse(token[1]);

            long num = n;
            List<long> myList = new List<long>();
           // myList.Contains(i)
            long h = (n%2==0)?n/2:n+1/2;
            for(int i=1;i<997 ;i++)
            {
                if(i>=num)
                     break;
                if(n%i==0)
                {
                     if(!myList.Contains(i))
                     myList.Add(i);
                     num =n / i;
                     if(!myList.Contains(num))
                     myList.Add(num);
                }

            }
            myList.Sort();
            long count = -1;
           //myList.Add(13);
            for(int i = 0;i<myList.Count;i++)
            {
                if(i==k-1)
                {
                    count = myList[i];
                    break;
                }
              // Console.WriteLine(myList[i]);
            }

            if(myList.Count<=1)
               count = 1;
             if(k>n)
             {
                 count = -1;
             }
            Console.WriteLine(count);

        }
    }
}

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

namespace KingsWay
{
    class Program
    {

        static void Main(string[] args)
        {
            string[] token = Console.ReadLine().Split();
            int n = int.Parse(token[0]);
            int k = int.Parse(token[1]);
            int count = 0;
            for(int i = 1;i<=n;i++)
            {
                if(n%i==0)
                {
                    count++;
                }
            }
            if(count < k)
             count = -1;

            Console.WriteLine(count);

        }
    }
}

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

namespace Codeforces
{
	class Program
	{
		static void Main(string[] args)
		{
			string input1 = Console.ReadLine();
			//string input2 = Console.ReadLine();

			//string input3 = Console.ReadLine();
			//string input4 = Console.ReadLine();

			var inputs1 = input1.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries).Select(long.Parse).ToArray();
			//var inputs2 = input2.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries).Select(long.Parse).ToArray();

			long n = inputs1[0];
			long k = inputs1[1];

			long count = 1;
			for (long i = 2; i <= (n + 1) / 2; i++)
			{
				if (n % i == 0)
				{
					count++;
				}

				if (count == k)
				{
					Console.WriteLine(i);
					return;
				}
			}

			if (count == k - 1)
			{
				Console.WriteLine(n);
			}
			else
			{
				Console.WriteLine(-1);
			}
		}

		public static void Print(int[] number)
		{
			var stringBuilder = new StringBuilder();
			foreach (var i in number)
			{
				if (i == 0 && stringBuilder.Length == 0)
				{
					continue;
				}

				stringBuilder.Append(i);
			}

			Console.WriteLine(stringBuilder.ToString());
		}

		public void Method1(ref int n1, ref int n2, ref int k1, ref int k2)
		{
			double a = (double)n1 / k1;
			double b = (double)n2 / k2;
			if (n1 >= n2 || (a >= b && a < 2 * b))
			{

			}
		}

		public void Method2(ref int n1, ref int n2, ref int k1, ref int k2)
		{
			double a = (double)n1 / k1;
			double b = (double)n2 / k2;
			if (n2 >= n1 || (b >= a && b < 2 * a))
			{

			}
		}

		public class Node
		{
			public int Count { get; set; }

			public int FirstIndex { get; set; } = -1;

			public int LastIndex { get; set; } = -1;
		}

		//public class Node<T>
		//{
		//	public Node<T> Left { get; set; }

		//	public Node<T> Right { get; set; }

		//	public T Value { get; set; }

		//	public Node(T value)
		//	{
		//		Value = value;
		//	}
		//}

		//public class Tree<T>
		//{
		//	public Node<T> Root { get; set; }

		//	public Tree(T value)
		//	{
		//		Root = new Node<T>(value);
		//	}
		//}

		private static long GCD(long a, long b)
		{
			long max = Math.Max(a, b);
			long min = Math.Min(a, b);

			if (min == 0)
			{
				return max;
			}

			a = min;
			b = max % min;
			return GCD(a, b);
		}

		private static long LCM(long a, long b)
		{
			return Math.Abs(a * b) / GCD(a, b);
		}

		//private static int Length(short[] a)
		//{
		//	int firstItemIndex = 0;
		//	for (int i = 0; i < a.Length; i++)
		//	{
		//		if (a[i] == 0)
		//		{
		//			continue;
		//		}

		//		firstItemIndex = i;
		//		break;
		//	}

		//	return a.Length - firstItemIndex;
		//}

		//private static short[] Subtract(short[] a, short[] b)
		//{
		//	if (a.Length != b.Length)
		//	{
		//		throw new ArgumentException();
		//	}

		//	short[] result = new short[a.Length];
		//	Array.Copy(a, result, a.Length);
		//	for (int i = result.Length - 1; i >= 0; i--)
		//	{
		//		if (result[i] < b[i])
		//		{
		//			int j = i - 1;
		//			while (result[j] == 0)
		//			{
		//				result[j--] = 9;
		//			}

		//			result[j]--;
		//			result[i] += 10;
		//		}

		//		result[i] -= b[i];
		//	}

		//	return result;
		//}

		//private static short[] Multiply(short[] a, int b)
		//{
		//	short[] result = new short[a.Length];
		//	for (int i = a.Length - 1; i > 0; i--)
		//	{
		//		int temp = a[i] * b;
		//		result[i] = (short)(result[i] + temp % 10);
		//		result[i - 1] = (short)(result[i - 1] + temp / 10);
		//	}

		//	return result;
		//}

		//private static int Mod(short[] a, int b)
		//{
		//	int rest = 0, i = 0;
		//	while (i < a.Length)
		//	{
		//		int d = 10 * rest + a[i];
		//		while (d < b && i < a.Length - 1)
		//		{
		//			d = 10 * d + a[++i];
		//		}

		//		rest = d % b;
		//		i++;
		//	}

		//	return rest;
		//}

		//private static short[] Divide(short[] a, int b)
		//{
		//	short[] result = new short[a.Length];
		//	int rest = 0, i = 0;
		//	while (i < a.Length)
		//	{
		//		int d = 10 * rest + a[i];
		//		while (d < b && i < a.Length - 1)
		//		{
		//			d = 10 * d + a[++i];
		//		}

		//		result[i] = (short)(d / b);
		//		rest = d % b;
		//		i++;
		//	}

		//	return result;
		//}
	}
}

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

namespace Codeforces
{
	class Program
	{
		static void Main(string[] args)
		{
			string input1 = Console.ReadLine();
			//string input2 = Console.ReadLine();

			//string input3 = Console.ReadLine();
			//string input4 = Console.ReadLine();

			var inputs1 = input1.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries).Select(long.Parse).ToArray();
			//var inputs2 = input2.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries).Select(long.Parse).ToArray();

			long n = inputs1[0];
			long k = inputs1[1];

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

			if (n == 1)
			{
				Console.WriteLine(-1);
				return;
			}

			var d = new List<long> { 1 };
			int index = 1;
			var border = n;

			var sqrt = Math.Sqrt(n);
			for (long i = 2; i < border; i++)
			{
				if (n % i == 0)
				{
					var res = n / i;
					d.Insert(index, res);
					if (i != res)
					{
						d.Insert(index, i);
					}

					index++;
					border = res;
					sqrt = Math.Sqrt(border);
				}

				if (i > sqrt)
				{
					if (d.Count == 1)
					{
						if (k == 2)
						{
							Console.WriteLine(n);
						}
						else
						{
							Console.WriteLine(-1);
						}

						return;
					}

					break;
				}
			}

			d.Insert(d.Count, n);

			if (d.Count >= k)
			{
				Console.WriteLine(d.ElementAt((int)(k - 1)));
			}
			else
			{
				Console.WriteLine(-1);
			}
		}

		public static void Print(int[] number)
		{
			var stringBuilder = new StringBuilder();
			foreach (var i in number)
			{
				if (i == 0 && stringBuilder.Length == 0)
				{
					continue;
				}

				stringBuilder.Append(i);
			}

			Console.WriteLine(stringBuilder.ToString());
		}

		public void Method1(ref int n1, ref int n2, ref int k1, ref int k2)
		{
			double a = (double)n1 / k1;
			double b = (double)n2 / k2;
			if (n1 >= n2 || (a >= b && a < 2 * b))
			{

			}
		}

		public void Method2(ref int n1, ref int n2, ref int k1, ref int k2)
		{
			double a = (double)n1 / k1;
			double b = (double)n2 / k2;
			if (n2 >= n1 || (b >= a && b < 2 * a))
			{

			}
		}

		public class Node
		{
			public int Count { get; set; }

			public int FirstIndex { get; set; } = -1;

			public int LastIndex { get; set; } = -1;
		}

		//public class Node<T>
		//{
		//	public Node<T> Left { get; set; }

		//	public Node<T> Right { get; set; }

		//	public T Value { get; set; }

		//	public Node(T value)
		//	{
		//		Value = value;
		//	}
		//}

		//public class Tree<T>
		//{
		//	public Node<T> Root { get; set; }

		//	public Tree(T value)
		//	{
		//		Root = new Node<T>(value);
		//	}
		//}

		private static long GCD(long a, long b)
		{
			long max = Math.Max(a, b);
			long min = Math.Min(a, b);

			if (min == 0)
			{
				return max;
			}

			a = min;
			b = max % min;
			return GCD(a, b);
		}

		private static long LCM(long a, long b)
		{
			return Math.Abs(a * b) / GCD(a, b);
		}

		//private static int Length(short[] a)
		//{
		//	int firstItemIndex = 0;
		//	for (int i = 0; i < a.Length; i++)
		//	{
		//		if (a[i] == 0)
		//		{
		//			continue;
		//		}

		//		firstItemIndex = i;
		//		break;
		//	}

		//	return a.Length - firstItemIndex;
		//}

		//private static short[] Subtract(short[] a, short[] b)
		//{
		//	if (a.Length != b.Length)
		//	{
		//		throw new ArgumentException();
		//	}

		//	short[] result = new short[a.Length];
		//	Array.Copy(a, result, a.Length);
		//	for (int i = result.Length - 1; i >= 0; i--)
		//	{
		//		if (result[i] < b[i])
		//		{
		//			int j = i - 1;
		//			while (result[j] == 0)
		//			{
		//				result[j--] = 9;
		//			}

		//			result[j]--;
		//			result[i] += 10;
		//		}

		//		result[i] -= b[i];
		//	}

		//	return result;
		//}

		//private static short[] Multiply(short[] a, int b)
		//{
		//	short[] result = new short[a.Length];
		//	for (int i = a.Length - 1; i > 0; i--)
		//	{
		//		int temp = a[i] * b;
		//		result[i] = (short)(result[i] + temp % 10);
		//		result[i - 1] = (short)(result[i - 1] + temp / 10);
		//	}

		//	return result;
		//}

		//private static int Mod(short[] a, int b)
		//{
		//	int rest = 0, i = 0;
		//	while (i < a.Length)
		//	{
		//		int d = 10 * rest + a[i];
		//		while (d < b && i < a.Length - 1)
		//		{
		//			d = 10 * d + a[++i];
		//		}

		//		rest = d % b;
		//		i++;
		//	}

		//	return rest;
		//}

		//private static short[] Divide(short[] a, int b)
		//{
		//	short[] result = new short[a.Length];
		//	int rest = 0, i = 0;
		//	while (i < a.Length)
		//	{
		//		int d = 10 * rest + a[i];
		//		while (d < b && i < a.Length - 1)
		//		{
		//			d = 10 * d + a[++i];
		//		}

		//		result[i] = (short)(d / b);
		//		rest = d % b;
		//		i++;
		//	}

		//	return result;
		//}
	}
}

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

namespace Codeforces
{
	class Program
	{
		static void Main(string[] args)
		{
			string input1 = Console.ReadLine();
			//string input2 = Console.ReadLine();

			//string input3 = Console.ReadLine();
			//string input4 = Console.ReadLine();

			var inputs1 = input1.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries).Select(long.Parse).ToArray();
			//var inputs2 = input2.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries).Select(long.Parse).ToArray();

			long n = inputs1[0];
			long k = inputs1[1];

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

			var d = new List<long> { 1 };
			int index = 1;
			var border = n;

			for (long i = 2; i < border; i++)
			{
				if (n % i == 0)
				{
					var res = n / i;
					d.Insert(index, res);
					d.Insert(index, i);

					index++;
					border = res;
				}
			}

			d.Insert(d.Count, n);

			if (d.Count >= k)
			{
				Console.WriteLine(d.ElementAt((int)(k - 1)));
			}
			else
			{
				Console.WriteLine(-1);
			}
		}

		public static void Print(int[] number)
		{
			var stringBuilder = new StringBuilder();
			foreach (var i in number)
			{
				if (i == 0 && stringBuilder.Length == 0)
				{
					continue;
				}

				stringBuilder.Append(i);
			}

			Console.WriteLine(stringBuilder.ToString());
		}

		public void Method1(ref int n1, ref int n2, ref int k1, ref int k2)
		{
			double a = (double)n1 / k1;
			double b = (double)n2 / k2;
			if (n1 >= n2 || (a >= b && a < 2 * b))
			{

			}
		}

		public void Method2(ref int n1, ref int n2, ref int k1, ref int k2)
		{
			double a = (double)n1 / k1;
			double b = (double)n2 / k2;
			if (n2 >= n1 || (b >= a && b < 2 * a))
			{

			}
		}

		public class Node
		{
			public int Count { get; set; }

			public int FirstIndex { get; set; } = -1;

			public int LastIndex { get; set; } = -1;
		}

		//public class Node<T>
		//{
		//	public Node<T> Left { get; set; }

		//	public Node<T> Right { get; set; }

		//	public T Value { get; set; }

		//	public Node(T value)
		//	{
		//		Value = value;
		//	}
		//}

		//public class Tree<T>
		//{
		//	public Node<T> Root { get; set; }

		//	public Tree(T value)
		//	{
		//		Root = new Node<T>(value);
		//	}
		//}

		private static long GCD(long a, long b)
		{
			long max = Math.Max(a, b);
			long min = Math.Min(a, b);

			if (min == 0)
			{
				return max;
			}

			a = min;
			b = max % min;
			return GCD(a, b);
		}

		private static long LCM(long a, long b)
		{
			return Math.Abs(a * b) / GCD(a, b);
		}

		//private static int Length(short[] a)
		//{
		//	int firstItemIndex = 0;
		//	for (int i = 0; i < a.Length; i++)
		//	{
		//		if (a[i] == 0)
		//		{
		//			continue;
		//		}

		//		firstItemIndex = i;
		//		break;
		//	}

		//	return a.Length - firstItemIndex;
		//}

		//private static short[] Subtract(short[] a, short[] b)
		//{
		//	if (a.Length != b.Length)
		//	{
		//		throw new ArgumentException();
		//	}

		//	short[] result = new short[a.Length];
		//	Array.Copy(a, result, a.Length);
		//	for (int i = result.Length - 1; i >= 0; i--)
		//	{
		//		if (result[i] < b[i])
		//		{
		//			int j = i - 1;
		//			while (result[j] == 0)
		//			{
		//				result[j--] = 9;
		//			}

		//			result[j]--;
		//			result[i] += 10;
		//		}

		//		result[i] -= b[i];
		//	}

		//	return result;
		//}

		//private static short[] Multiply(short[] a, int b)
		//{
		//	short[] result = new short[a.Length];
		//	for (int i = a.Length - 1; i > 0; i--)
		//	{
		//		int temp = a[i] * b;
		//		result[i] = (short)(result[i] + temp % 10);
		//		result[i - 1] = (short)(result[i - 1] + temp / 10);
		//	}

		//	return result;
		//}

		//private static int Mod(short[] a, int b)
		//{
		//	int rest = 0, i = 0;
		//	while (i < a.Length)
		//	{
		//		int d = 10 * rest + a[i];
		//		while (d < b && i < a.Length - 1)
		//		{
		//			d = 10 * d + a[++i];
		//		}

		//		rest = d % b;
		//		i++;
		//	}

		//	return rest;
		//}

		//private static short[] Divide(short[] a, int b)
		//{
		//	short[] result = new short[a.Length];
		//	int rest = 0, i = 0;
		//	while (i < a.Length)
		//	{
		//		int d = 10 * rest + a[i];
		//		while (d < b && i < a.Length - 1)
		//		{
		//			d = 10 * d + a[++i];
		//		}

		//		result[i] = (short)(d / b);
		//		rest = d % b;
		//		i++;
		//	}

		//	return result;
		//}
	}
}

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

namespace Codeforces
{
	class Program
	{
		static void Main(string[] args)
		{
			string input1 = Console.ReadLine();
			//string input2 = Console.ReadLine();

			//string input3 = Console.ReadLine();
			//string input4 = Console.ReadLine();

			var inputs1 = input1.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries).Select(long.Parse).ToArray();
			//var inputs2 = input2.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries).Select(long.Parse).ToArray();

			long n = inputs1[0];
			long k = inputs1[1];

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

			if (n == 1)
			{
				Console.WriteLine(-1);
				return;
			}

			var d = new List<long> { 1 };
			int index = 1;
			var border = n;

			var sqrt = Math.Sqrt(n);
			for (long i = 2; i < (border / 2) + 1; i++)
			{
				if (n % i == 0)
				{
					var res = n / i;
					d.Insert(index, res);
					if (i != res)
					{
						d.Insert(index, i);
					}

					index++;
					border = res;
				}

				if (i > sqrt)
				{
					if (d.Count == 1)
					{
						if (k == 2)
						{
							Console.WriteLine(n);
						}
						else
						{
							Console.WriteLine(-1);
						}

						return;
					}
				}
			}

			d.Insert(d.Count, n);

			if (d.Count >= k)
			{
				Console.WriteLine(d.ElementAt((int)(k - 1)));
			}
			else
			{
				Console.WriteLine(-1);
			}
		}

		public static void Print(int[] number)
		{
			var stringBuilder = new StringBuilder();
			foreach (var i in number)
			{
				if (i == 0 && stringBuilder.Length == 0)
				{
					continue;
				}

				stringBuilder.Append(i);
			}

			Console.WriteLine(stringBuilder.ToString());
		}

		public void Method1(ref int n1, ref int n2, ref int k1, ref int k2)
		{
			double a = (double)n1 / k1;
			double b = (double)n2 / k2;
			if (n1 >= n2 || (a >= b && a < 2 * b))
			{

			}
		}

		public void Method2(ref int n1, ref int n2, ref int k1, ref int k2)
		{
			double a = (double)n1 / k1;
			double b = (double)n2 / k2;
			if (n2 >= n1 || (b >= a && b < 2 * a))
			{

			}
		}

		public class Node
		{
			public int Count { get; set; }

			public int FirstIndex { get; set; } = -1;

			public int LastIndex { get; set; } = -1;
		}

		//public class Node<T>
		//{
		//	public Node<T> Left { get; set; }

		//	public Node<T> Right { get; set; }

		//	public T Value { get; set; }

		//	public Node(T value)
		//	{
		//		Value = value;
		//	}
		//}

		//public class Tree<T>
		//{
		//	public Node<T> Root { get; set; }

		//	public Tree(T value)
		//	{
		//		Root = new Node<T>(value);
		//	}
		//}

		private static long GCD(long a, long b)
		{
			long max = Math.Max(a, b);
			long min = Math.Min(a, b);

			if (min == 0)
			{
				return max;
			}

			a = min;
			b = max % min;
			return GCD(a, b);
		}

		private static long LCM(long a, long b)
		{
			return Math.Abs(a * b) / GCD(a, b);
		}

		//private static int Length(short[] a)
		//{
		//	int firstItemIndex = 0;
		//	for (int i = 0; i < a.Length; i++)
		//	{
		//		if (a[i] == 0)
		//		{
		//			continue;
		//		}

		//		firstItemIndex = i;
		//		break;
		//	}

		//	return a.Length - firstItemIndex;
		//}

		//private static short[] Subtract(short[] a, short[] b)
		//{
		//	if (a.Length != b.Length)
		//	{
		//		throw new ArgumentException();
		//	}

		//	short[] result = new short[a.Length];
		//	Array.Copy(a, result, a.Length);
		//	for (int i = result.Length - 1; i >= 0; i--)
		//	{
		//		if (result[i] < b[i])
		//		{
		//			int j = i - 1;
		//			while (result[j] == 0)
		//			{
		//				result[j--] = 9;
		//			}

		//			result[j]--;
		//			result[i] += 10;
		//		}

		//		result[i] -= b[i];
		//	}

		//	return result;
		//}

		//private static short[] Multiply(short[] a, int b)
		//{
		//	short[] result = new short[a.Length];
		//	for (int i = a.Length - 1; i > 0; i--)
		//	{
		//		int temp = a[i] * b;
		//		result[i] = (short)(result[i] + temp % 10);
		//		result[i - 1] = (short)(result[i - 1] + temp / 10);
		//	}

		//	return result;
		//}

		//private static int Mod(short[] a, int b)
		//{
		//	int rest = 0, i = 0;
		//	while (i < a.Length)
		//	{
		//		int d = 10 * rest + a[i];
		//		while (d < b && i < a.Length - 1)
		//		{
		//			d = 10 * d + a[++i];
		//		}

		//		rest = d % b;
		//		i++;
		//	}

		//	return rest;
		//}

		//private static short[] Divide(short[] a, int b)
		//{
		//	short[] result = new short[a.Length];
		//	int rest = 0, i = 0;
		//	while (i < a.Length)
		//	{
		//		int d = 10 * rest + a[i];
		//		while (d < b && i < a.Length - 1)
		//		{
		//			d = 10 * d + a[++i];
		//		}

		//		result[i] = (short)(d / b);
		//		rest = d % b;
		//		i++;
		//	}

		//	return result;
		//}
	}
}

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

namespace Codeforces
{
	class Program
	{
		static void Main(string[] args)
		{
			string input1 = Console.ReadLine();
			//string input2 = Console.ReadLine();

			//string input3 = Console.ReadLine();
			//string input4 = Console.ReadLine();

			var inputs1 = input1.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries).Select(long.Parse).ToArray();
			//var inputs2 = input2.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries).Select(long.Parse).ToArray();

			long n = inputs1[0];
			long k = inputs1[1];

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

			if (n == 1)
			{
				Console.WriteLine(-1);
				return;
			}

			var d = new List<long> { 1 };
			int index = 1;
			var border = n;

			for (long i = 2; i < border; i++)
			{
				if (n % i == 0)
				{
					var res = n / i;
					d.Insert(index, res);
					d.Insert(index, i);

					index++;
					border = res;
				}
			}

			d.Insert(d.Count, n);

			if (d.Count >= k)
			{
				Console.WriteLine(d.ElementAt((int)(k - 1)));
			}
			else
			{
				Console.WriteLine(-1);
			}
		}

		public static void Print(int[] number)
		{
			var stringBuilder = new StringBuilder();
			foreach (var i in number)
			{
				if (i == 0 && stringBuilder.Length == 0)
				{
					continue;
				}

				stringBuilder.Append(i);
			}

			Console.WriteLine(stringBuilder.ToString());
		}

		public void Method1(ref int n1, ref int n2, ref int k1, ref int k2)
		{
			double a = (double)n1 / k1;
			double b = (double)n2 / k2;
			if (n1 >= n2 || (a >= b && a < 2 * b))
			{

			}
		}

		public void Method2(ref int n1, ref int n2, ref int k1, ref int k2)
		{
			double a = (double)n1 / k1;
			double b = (double)n2 / k2;
			if (n2 >= n1 || (b >= a && b < 2 * a))
			{

			}
		}

		public class Node
		{
			public int Count { get; set; }

			public int FirstIndex { get; set; } = -1;

			public int LastIndex { get; set; } = -1;
		}

		//public class Node<T>
		//{
		//	public Node<T> Left { get; set; }

		//	public Node<T> Right { get; set; }

		//	public T Value { get; set; }

		//	public Node(T value)
		//	{
		//		Value = value;
		//	}
		//}

		//public class Tree<T>
		//{
		//	public Node<T> Root { get; set; }

		//	public Tree(T value)
		//	{
		//		Root = new Node<T>(value);
		//	}
		//}

		private static long GCD(long a, long b)
		{
			long max = Math.Max(a, b);
			long min = Math.Min(a, b);

			if (min == 0)
			{
				return max;
			}

			a = min;
			b = max % min;
			return GCD(a, b);
		}

		private static long LCM(long a, long b)
		{
			return Math.Abs(a * b) / GCD(a, b);
		}

		//private static int Length(short[] a)
		//{
		//	int firstItemIndex = 0;
		//	for (int i = 0; i < a.Length; i++)
		//	{
		//		if (a[i] == 0)
		//		{
		//			continue;
		//		}

		//		firstItemIndex = i;
		//		break;
		//	}

		//	return a.Length - firstItemIndex;
		//}

		//private static short[] Subtract(short[] a, short[] b)
		//{
		//	if (a.Length != b.Length)
		//	{
		//		throw new ArgumentException();
		//	}

		//	short[] result = new short[a.Length];
		//	Array.Copy(a, result, a.Length);
		//	for (int i = result.Length - 1; i >= 0; i--)
		//	{
		//		if (result[i] < b[i])
		//		{
		//			int j = i - 1;
		//			while (result[j] == 0)
		//			{
		//				result[j--] = 9;
		//			}

		//			result[j]--;
		//			result[i] += 10;
		//		}

		//		result[i] -= b[i];
		//	}

		//	return result;
		//}

		//private static short[] Multiply(short[] a, int b)
		//{
		//	short[] result = new short[a.Length];
		//	for (int i = a.Length - 1; i > 0; i--)
		//	{
		//		int temp = a[i] * b;
		//		result[i] = (short)(result[i] + temp % 10);
		//		result[i - 1] = (short)(result[i - 1] + temp / 10);
		//	}

		//	return result;
		//}

		//private static int Mod(short[] a, int b)
		//{
		//	int rest = 0, i = 0;
		//	while (i < a.Length)
		//	{
		//		int d = 10 * rest + a[i];
		//		while (d < b && i < a.Length - 1)
		//		{
		//			d = 10 * d + a[++i];
		//		}

		//		rest = d % b;
		//		i++;
		//	}

		//	return rest;
		//}

		//private static short[] Divide(short[] a, int b)
		//{
		//	short[] result = new short[a.Length];
		//	int rest = 0, i = 0;
		//	while (i < a.Length)
		//	{
		//		int d = 10 * rest + a[i];
		//		while (d < b && i < a.Length - 1)
		//		{
		//			d = 10 * d + a[++i];
		//		}

		//		result[i] = (short)(d / b);
		//		rest = d % b;
		//		i++;
		//	}

		//	return result;
		//}
	}
}

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

namespace Codeforces
{
	class Program
	{
		static void Main(string[] args)
		{
			string input1 = Console.ReadLine();
			//string input2 = Console.ReadLine();

			//string input3 = Console.ReadLine();
			//string input4 = Console.ReadLine();

			var inputs1 = input1.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries).Select(long.Parse).ToArray();
			//var inputs2 = input2.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries).Select(long.Parse).ToArray();

			long n = inputs1[0];
			long k = inputs1[1];

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

			var d = new List<long>();
			int index = 0;
			var border = n / 2;

			for (long i = 2; i <= border; i++)
			{
				if (n % i == 0)
				{
					var res = n / i;
					d.Insert(index, res);
					d.Insert(index, i);

					index++;
					border = res;
				}
			}

			if (d.Count > k)
			{
				Console.WriteLine(d.ElementAt((int)k));
				return;
			}

			if (d.Count == k)
			{
				Console.WriteLine(n);
			}
			else
			{
				Console.WriteLine(-1);
			}
		}

		public static void Print(int[] number)
		{
			var stringBuilder = new StringBuilder();
			foreach (var i in number)
			{
				if (i == 0 && stringBuilder.Length == 0)
				{
					continue;
				}

				stringBuilder.Append(i);
			}

			Console.WriteLine(stringBuilder.ToString());
		}

		public void Method1(ref int n1, ref int n2, ref int k1, ref int k2)
		{
			double a = (double)n1 / k1;
			double b = (double)n2 / k2;
			if (n1 >= n2 || (a >= b && a < 2 * b))
			{

			}
		}

		public void Method2(ref int n1, ref int n2, ref int k1, ref int k2)
		{
			double a = (double)n1 / k1;
			double b = (double)n2 / k2;
			if (n2 >= n1 || (b >= a && b < 2 * a))
			{

			}
		}

		public class Node
		{
			public int Count { get; set; }

			public int FirstIndex { get; set; } = -1;

			public int LastIndex { get; set; } = -1;
		}

		//public class Node<T>
		//{
		//	public Node<T> Left { get; set; }

		//	public Node<T> Right { get; set; }

		//	public T Value { get; set; }

		//	public Node(T value)
		//	{
		//		Value = value;
		//	}
		//}

		//public class Tree<T>
		//{
		//	public Node<T> Root { get; set; }

		//	public Tree(T value)
		//	{
		//		Root = new Node<T>(value);
		//	}
		//}

		private static long GCD(long a, long b)
		{
			long max = Math.Max(a, b);
			long min = Math.Min(a, b);

			if (min == 0)
			{
				return max;
			}

			a = min;
			b = max % min;
			return GCD(a, b);
		}

		private static long LCM(long a, long b)
		{
			return Math.Abs(a * b) / GCD(a, b);
		}

		//private static int Length(short[] a)
		//{
		//	int firstItemIndex = 0;
		//	for (int i = 0; i < a.Length; i++)
		//	{
		//		if (a[i] == 0)
		//		{
		//			continue;
		//		}

		//		firstItemIndex = i;
		//		break;
		//	}

		//	return a.Length - firstItemIndex;
		//}

		//private static short[] Subtract(short[] a, short[] b)
		//{
		//	if (a.Length != b.Length)
		//	{
		//		throw new ArgumentException();
		//	}

		//	short[] result = new short[a.Length];
		//	Array.Copy(a, result, a.Length);
		//	for (int i = result.Length - 1; i >= 0; i--)
		//	{
		//		if (result[i] < b[i])
		//		{
		//			int j = i - 1;
		//			while (result[j] == 0)
		//			{
		//				result[j--] = 9;
		//			}

		//			result[j]--;
		//			result[i] += 10;
		//		}

		//		result[i] -= b[i];
		//	}

		//	return result;
		//}

		//private static short[] Multiply(short[] a, int b)
		//{
		//	short[] result = new short[a.Length];
		//	for (int i = a.Length - 1; i > 0; i--)
		//	{
		//		int temp = a[i] * b;
		//		result[i] = (short)(result[i] + temp % 10);
		//		result[i - 1] = (short)(result[i - 1] + temp / 10);
		//	}

		//	return result;
		//}

		//private static int Mod(short[] a, int b)
		//{
		//	int rest = 0, i = 0;
		//	while (i < a.Length)
		//	{
		//		int d = 10 * rest + a[i];
		//		while (d < b && i < a.Length - 1)
		//		{
		//			d = 10 * d + a[++i];
		//		}

		//		rest = d % b;
		//		i++;
		//	}

		//	return rest;
		//}

		//private static short[] Divide(short[] a, int b)
		//{
		//	short[] result = new short[a.Length];
		//	int rest = 0, i = 0;
		//	while (i < a.Length)
		//	{
		//		int d = 10 * rest + a[i];
		//		while (d < b && i < a.Length - 1)
		//		{
		//			d = 10 * d + a[++i];
		//		}

		//		result[i] = (short)(d / b);
		//		rest = d % b;
		//		i++;
		//	}

		//	return result;
		//}
	}
}