public ArrayList<Integer> spiralReading(int [][] matrix){
        ArrayList<Integer> result =  new ArrayList<Integer>();
        int a, a1, a2, b, b1, b2;

        b1 = 0;
        b2 = matrix.length - 1;
        if(b2 < 0)
            return result;
        a1 = 0;
        a2 = matrix[0].length - 1;

        while((a2 - a1 >= 0) && (b2 - b1 >= 0)){
            for(a = a1; a <= a2; a++)
                result.add(matrix[b1][a]);
            if(b1 == b2)
               break;
            for(b = b1 + 1; b <= b2; b++)
                result.add(matrix[b][a2]);
            if(a1==a2)
                break;
            for(a = a2 - 1; a >= a1; a--)
                result.add(matrix[b2][a]);
            for(b = b2 - 1; b > b1; b-- )
                result.add(matrix[b][a1]);
            a1++;
            a2--;
            b1++;
            b2--;
        }
        return result;
    }