Use minimum length of input and output for N.

This needs to be applied to all functions.