Wouldn't a loop be nicer here? If you make the right loops you will be able to specify N at the top of the script and everything will run.