Finite size effects and the mass gap of the O(N) model for arbitrary values of N