Most simple way - to use binary search. But maybe possible in different ways)
*rules in the top of screen