n, c = map(int, input().split())

ns = [list(map(lambda x: bin(int(x))[2:].rjust(n, '0'), input().split())) for _ in range(c)]

from itertools import permutations
def find(l):
    ans = []
    for p in permutations(range(n)):
        if all(x[i] == y[p[i]] for x, y in l for i in range(n)):
            return p

def solve(p):
    ans = []
    for k in range(n):
        s = bin(1 << k)[2:].rjust(n, '0')
        ls = [None] * n
        for i, c in enumerate(s):
            ls[p[i]] = s[i]
        ans.append(int(''.join(ls), 2))
    return " ".join(map(str, ans))

_p = find(ns)
print(solve(_p))

Embed on website

To embed this program on your website, copy the following code and paste it into your website's HTML: