I am not sure which part of the code is creating an infinite loop when there are no -1s