Topological charge on the lattice. The 2D CP(N-1) model