Problem statement

https://binarysearch.com/problems/Smallest-Intersecting-Element/

Solution

Just do intersection of sets.

Complexity

It is O(mn) for time and O(m) for space.

Code

class Solution:
    def solve(self, M):
        if not M: return -1
        s = set(M[0])
        for row in M[1:]:
            s = s & set(row)
        return min(s) if s else -1