Buggy python submission (verdict: Time Limit Exceeded):
n, m = map(int, input().split())
a = [list(map(int, input().split())) for _ in range(n)]

s = set([])
ans = n
for _ in range(m):
    memo = [0] * (m + 1)
    flag = [0] * (n + 1)
    for j in range(m):
        for i in range(n):
            if flag[i] == 0 and a[i][j] not in s:
                memo[a[i][j]] += 1
                flag[i] = 1
    idx = 0
    mmax = 0
    for i, me in enumerate(memo):
        if me > mmax:
            idx = i
            mmax = me

    ans = min(ans, mmax)
    s.add(idx)

print(ans)





Fixed submission:
n, m = map(int, input().split())
a = [list(map(int, input().split())) for _ in range(n)]

s = set([])
ans = n
for _ in range(m):
    memo = [0] * (m + 1)
    flag = [0] * (n + 1)
    for j in range(m):
        for i in range(n):
            if flag[i] == 0 and a[i][j] not in s:
                memo[a[i][j]] += 1
                flag[i] = 1
    idx = 0
    mmax = 0
    for i, me in enumerate(memo):
        if me > mmax:
            idx = i
            mmax = me

    ans = min(ans, mmax)
    s.add(idx)

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline

n, m = map(int, input().split())
a = [list(map(int, input().split())) for _ in range(n)]

left = 0
right = n
while right - left > 1:
    mid = (right + left) // 2
    ans = False
    s = set([i+1 for i in range(m)])
    while s:
        memo = [0] * (m + 1)
        flag = [0] * (n + 1)
        for j in range(m):
            for i in range(n):
                if flag[i] == 0 and a[i][j] in s:
                    memo[a[i][j]] += 1
                    flag[i] = 1
                    if memo[a[i][j]] > mid:
                        s.remove(a[i][j])
                        break
            else:
                continue
            break

        if max(memo) <= mid:
            ans = True
            break
    if ans:
        right = mid
    else:
        left = mid
print(right)



Fixed submission:
n, m = map(int, input().split())
a = [list(map(int, input().split())) for _ in range(n)]

s = set([])
ans = n
for _ in range(m):
    memo = [0] * (m + 1)
    flag = [0] * (n + 1)
    for j in range(m):
        for i in range(n):
            if flag[i] == 0 and a[i][j] not in s:
                memo[a[i][j]] += 1
                flag[i] = 1
    idx = 0
    mmax = 0
    for i, me in enumerate(memo):
        if me > mmax:
            idx = i
            mmax = me

    ans = min(ans, mmax)
    s.add(idx)

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline

n, m = map(int, input().split())
a = [list(map(int, input().split())) for _ in range(n)]

left = 0
right = n
while right - left > 1:
    mid = (right + left) // 2
    ans = False
    s = set([i+1 for i in range(m)])
    while s:
        memo = [0] * (m + 1)
        flag = [0] * (n + 1)
        for j in range(m):
            for i in range(n):
                if flag[i] == 0 and a[i][j] in s:
                    memo[a[i][j]] += 1
                    flag[i] = 1
                    if memo[a[i][j]] > mid:
                        s.remove(a[i][j])
                        break
            else:
                continue
            break

        if max(memo) <= mid:
            ans = True
            break
    if ans:
        right = mid
    else:
        left = mid
print(right)



Fixed submission:
n, m = map(int, input().split())
a = [list(map(int, input().split())) for _ in range(n)]

s = set([])
ans = n
for _ in range(m):
    memo = [0] * (m + 1)
    flag = [0] * (n + 1)
    for j in range(m):
        for i in range(n):
            if flag[i] == 0 and a[i][j] not in s:
                memo[a[i][j]] += 1
                flag[i] = 1
    idx = 0
    mmax = 0
    for i, me in enumerate(memo):
        if me > mmax:
            idx = i
            mmax = me

    ans = min(ans, mmax)
    s.add(idx)

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n, m = map(int, input().split())
a = [list(map(int, input().split())) for _ in range(n)]

left = 0
right = n
while right - left > 1:
    mid = (right + left) // 2
    ans = False
    s = set([i+1 for i in range(m)])
    while s:
        memo = [0] * (m + 1)
        flag = [0] * (n + 1)
        for j in range(m):
            for i in range(n):
                if flag[i] == 0 and a[i][j] in s:
                    memo[a[i][j]] += 1
                    flag[i] = 1
                    if memo[a[i][j]] > mid:
                        s.remove(a[i][j])
                        break
            else:
                continue
            break

        if max(memo) <= mid:
            ans = True
            break
    if ans:
        right = mid
    else:
        left = mid
print(right)



Fixed submission:
n, m = map(int, input().split())
a = [list(map(int, input().split())) for _ in range(n)]

s = set([])
ans = n
for _ in range(m):
    memo = [0] * (m + 1)
    flag = [0] * (n + 1)
    for j in range(m):
        for i in range(n):
            if flag[i] == 0 and a[i][j] not in s:
                memo[a[i][j]] += 1
                flag[i] = 1
    idx = 0
    mmax = 0
    for i, me in enumerate(memo):
        if me > mmax:
            idx = i
            mmax = me

    ans = min(ans, mmax)
    s.add(idx)

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n, m = map(int, input().split())
a = [list(map(int, input().split())) for _ in range(n)]

left = 0
right = n
while right - left > 1:
    mid = (right + left) // 2
    ans = False
    s = set([i+1 for i in range(m)])
    while s:
        memo = [0] * (m + 1)
        flag = [0] * (n + 1)
        for j in range(m):
            for i in range(n):
                if flag[i] == 0 and a[i][j] in s:
                    memo[a[i][j]] += 1
                    flag[i] = 1
                    if memo[a[i][j]] > mid:
                        s.remove(a[i][j])
                        break
            else:
                continue
            break

        if max(memo) <= mid:
            ans = True
            break
    if ans:
        right = mid
    else:
        left = mid
print(right)



Fixed submission:
n, m = map(int, input().split())
a = [list(map(int, input().split())) for _ in range(n)]

s = set([])
ans = n
for _ in range(m):
    memo = [0] * (m + 1)
    flag = [0] * (n + 1)
    for j in range(m):
        for i in range(n):
            if flag[i] == 0 and a[i][j] not in s:
                memo[a[i][j]] += 1
                flag[i] = 1
    idx = 0
    mmax = 0
    for i, me in enumerate(memo):
        if me > mmax:
            idx = i
            mmax = me

    ans = min(ans, mmax)
    s.add(idx)

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n, m = map(int, input().split())
a = [list(map(int, input().split())) for _ in range(n)]

for k in range(1, n+1):
    s = set([i+1 for i in range(m)])
    while s:
        memo = [0] * (m + 1)
        flag = [0] * (n + 1)
        for j in range(m):
            for i in range(n):
                if flag[i] == 0 and a[i][j] in s:
                    memo[a[i][j]] += 1
                    flag[i] = 1
                    if memo[a[i][j]] > k:
                        s.remove(a[i][j])
                        break
            else:
                continue
            break
        if max(memo) <= k:
            print(k)
            exit()



Fixed submission:
n, m = map(int, input().split())
a = [list(map(int, input().split())) for _ in range(n)]

s = set([])
ans = n
for _ in range(m):
    memo = [0] * (m + 1)
    flag = [0] * (n + 1)
    for j in range(m):
        for i in range(n):
            if flag[i] == 0 and a[i][j] not in s:
                memo[a[i][j]] += 1
                flag[i] = 1
    idx = 0
    mmax = 0
    for i, me in enumerate(memo):
        if me > mmax:
            idx = i
            mmax = me

    ans = min(ans, mmax)
    s.add(idx)

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n, m = map(int, input().split())
a = [list(map(int, input().split())) for _ in range(n)]

for k in range(1, n+1):
    s = set([i+1 for i in range(m)])
    while s:
        memo = [0] * (m + 1)
        flag = [0] * (n + 1)
        for j in range(m):
            for i in range(n):
                if flag[i] == 0 and a[i][j] in s:
                    memo[a[i][j]] += 1
                    flag[i] = 1
                    if memo[a[i][j]] > k:
                        s.remove(a[i][j])
                        break
            else:
                continue
            break
        if max(memo) <= k:
            print(k)
            exit()



Fixed submission:
n, m = map(int, input().split())
a = [list(map(int, input().split())) for _ in range(n)]

s = set([])
ans = n
for _ in range(m):
    memo = [0] * (m + 1)
    flag = [0] * (n + 1)
    for j in range(m):
        for i in range(n):
            if flag[i] == 0 and a[i][j] not in s:
                memo[a[i][j]] += 1
                flag[i] = 1
    idx = 0
    mmax = 0
    for i, me in enumerate(memo):
        if me > mmax:
            idx = i
            mmax = me

    ans = min(ans, mmax)
    s.add(idx)

print(ans)