Find-s algorithm