Calculation of n*m squares