Time: O(m*n), Space: O(m*n)