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

class Program
{
    static void Main(string[] args)
    {
        int B = int.Parse(Console.ReadLine());
        int D = int.Parse(Console.ReadLine());
        StringBuilder sb = new StringBuilder();
        sb.Append("0");
        int i = 1;

        while(sb.Length <= D)
        {
            sb.Append(Convert.ToString(B, i));
            i++;
        }

        Console.WriteLine(sb.ToString().Substring(D, 1));
    }
}