A two-loop calculation of the mass gap for the O(N) model in finite volume