public int compareTo(M m) {
		if (total != m.total) return total - m.total;
		if (width != m.width) return width - m.width;
		if (height != m.height) return height - m.height;
		for (int x = 0; x < width; x++) for (int y = 0; y < height; y++)
			if (item(x, y) != m.item(x, y)) return item(x, y) - m.item(x, y) > 0 ? 1 : -1;
		return 0;
	}