Solution for indexJ