\[g=\tfrac{1}{2}\max\left(2\max_{0\leq k\leq 3}m_{k},1+N-(1+(-1)^{N})\left(%
\tfrac{1}{2}+\min_{0\leq k\leq 3}m_{k}\right)\right).\]