Two-way automata making choices only at the endmarkers