  We derive the optimal N-photon two-mode input state for obtaining an estimate
\phi of the phase difference between two arms of an interferometer. For an
optimal measurement [B. C. Sanders and G. J. Milburn, Phys. Rev. Lett. 75, 2944
(1995)], it yields a variance (\Delta \phi)^2 \simeq \pi^2/N^2, compared to
O(N^{-1}) or O(N^{-1/2}) for states considered by previous authors. Such a
measurement cannot be realized by counting photons in the interferometer
outputs. However, we introduce an adaptive measurement scheme that can be thus
realized, and show that it yields a variance in \phi very close to that from an
optimal measurement.
