First segmentation algorithm