private int getMaxLength() {
        int max_length = 0;
        for (int j=0; j<height; j++) {
            for (int i=0; i<width; i++) {
                max_length = Math.max(max_length, lengths2d[j][i]);
            }
        }
        return max_length;
    }