Time: O(logN + logM), Space: O(1)