Finding the index of the smallest element