first version with complexity of 2