import java.util.*; import java.io.BufferedReader; import java.io.InputStreamReader; import java.util.ArrayList; import java.util.Arrays; import java.util.List;
public class Main { public static void main(String[] args) { BufferedReader bf = new BufferedReader(new InputStreamReader(System.in)); String str; int K = 0; List values = new ArrayList<>(); Integer result = -1; try { while ((str = bf.readLine()) != null) { if (str.equals("")) { break; } K = Integer.parseInt(str.substring(str.lastIndexOf(",") + 1)); values = Arrays.asList(str.substring(1, str.lastIndexOf("]")).split(",")); if (values.size() > 0) { result = findIndex(values, K, 0, values.size() - 1); } } } catch (Exception e) { e.printStackTrace(); } System.out.println(result); }
public static int findIndex(List<String> list, int target, int begin, int end) {
int mid = (begin + end + 1) / 2;
if (begin == mid || end == mid) {
if (Integer.parseInt(list.get(begin)) == target) {
return begin;
} else if (Integer.parseInt(list.get(end)) == target) {
return end;
}
return -1;
}
if (Integer.parseInt(list.get(mid)) >= target) {
return findIndex(list, target, begin, mid);
} else if (Integer.parseInt(list.get(mid)) < target) {
return findIndex(list, target, mid + 1, end);
}
return -1;
}
}