let leading_ones s =
  let by = Bytes.of_string s in
  let ones = Bytes.map (fun c -> if c = '1' then '1' else 'x') by in
  let left = Bytes.index ones 'x' in
  left

let solve s i = match i with
  | i when i <= (leading_ones s) -> '1'
  | _ ->
     let by = Bytes.of_string s in
     let non_one = Bytes.map (fun c -> if c = '1' then ' ' else c) by in
     let trimmed = Bytes.trim non_one in
     trimmed.[0]

let () =
  let rec read () =
    try let ans = (Scanf.scanf "%s\n%i\n" solve) in
        Printf.printf "%c\n" ans
    with End_of_file -> ()
  in
  read ()
;;
