toInt :: String -> Int
toInt = read :: String -> Int

getKthNumber :: String -> Int -> Int
getKthNumber s k
  | nk <= 0 = n
  | otherwise = getKthNumber ns nk
      where
        n = toInt $ take 1 s
        ns = tail s
        nk 
          | n == 1 = k - 1
          | otherwise = k - n * 5000000000000000

main = do
  s <- getLine
  k <- toInt <$> getLine
  putStrLn $ show $ getKthNumber s k
