import Debug.Trace


solve :: [Int] -> Int -> Int
solve (h:t) x
    | x == 1 = h
    | h == 1 = solve t (x-1)
    | otherwise = h

main :: IO ()
main = do
    s <- getLine
    x <- read <$> getLine
    let split = map (:[]) s
    let a = map read split
    print (solve a x)
    main

