Replaced if N>0 by   if (N>0)&&(M>0)		# Flipped ports exist