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