Abstract. To each ribbon graph we assign a so-called L-space, which is a Lagrangian subspace in an even-dimensional vector space with the standard symplectic form. This invariant generalizes the notion of the intersection matrix of a chord diagram. Moreover, the actions of Morse perestroikas (or taking a partial dual) and Vassiliev moves on ribbon graphs are reinterpreted nicely in the language of L-spaces, becoming changes of bases in this vector space. Finally, we define a bialgebra structure on the span of L-spaces, which is analogous to the 4-bialgebra structure on chord diagrams.