Finished the first version but it is not working properly (result is always 1)