N unit cubes are assembled to form a larger cube (N is a positive integer.)

In the larger cube thus assembled, some of the faces are then painted.

The cube is now taken apart and it is found that 271 of the unit cubes have paint on them.

Find N.