Simple O(nm) space solution