Build a matrix with overbrace on some columns

I need to create a matrix and some overbraces on some entries at the top of the matrix like the following image(the entries are omitted)

I tried this code

$$A_n = \begin{bmatrix} a_1&b_{1,2}&\overbrace{0, \cdots, 0}^{N_1-1}&b_{1,S_1+1}&\overbrace{0, \cdots, 0}^{N_2-1} \end{bmatrix}$$


and this was the result. I don't want the overbrace to be inside the matrix

How can I do that?

\documentclass{article}
\makebox[0pt][l]{$\smash{\overbrace{\phantom{% \begin{matrix}#2\end{matrix}}}^{\text{#1}}}$}#2}
$$\begin{matrix} A_n = \begin{bmatrix} a_1&b_{1,2}&\bovermat{1}{0,\cdots,0} & b_{1,s_{1}+1} & \bovermat{2}{0,\cdots,0}\\ \end{bmatrix} \end{matrix}$$