
< 		if (mas.last > max) {
---
> 		if (mas.last > max && max + 1 < mas.last) {
