Harryxun/sft_time huggingface dataset:
### BUGGY CODE ###

N,M=list(map(int,input().strip().split(" ")))
keys=[]
want=2**N-1
for _ in range(M):
    a,b=list(map(int,input().strip().split(" ")))
    c=list(map(int,input().strip().split(" ")))
    temp=0
    for i in c:
        temp+=2**(i-1)
    keys+=[(a,temp)]

dp=[float("inf")]*(2**N)
dp[0]=0
for i in range(len(dp)):
    for j in range(len(keys)):
        price,val=keys[j]
        if i&val==0:
            continue
        dp[i]=min(dp[i-(i&val)]+price,dp[i])
        #print(keys[j])
        #print(dp[i],i,i&val)        
#print(keys)
#print(dp)
if dp[-1]==float("inf"):
    print(-1)
else:
    print(dp[-1])




### FIXED CODE ###

N,M=list(map(int,input().strip().split(" ")))
keys=[]
want=2**N-1
for _ in range(M):
    a,b=list(map(int,input().strip().split(" ")))
    c=list(map(int,input().strip().split(" ")))
    temp=0
    for i in c:
        temp+=2**(i-1)
    keys+=[(a,temp)]

dp=[float("inf")]*(2**N)
dp[0]=0
for i in range(len(dp)):
    for j in range(len(keys)):
        price,val=keys[j]
        if i&val==0:
            continue
        dp[i]=min(dp[i-(i&val)]+price,dp[i])
        #print(keys[j])
        #print(dp[i],i,i&val)        
#print(keys)
#print(dp)
if dp[-1]==float("inf"):
    print(-1)
else:
    print(dp[-1])
### BUGGY CODE ###

import sys
sys.setrecursionlimit(10 ** 9)
input = sys.stdin.readline

N, M = map(int, input().split())
check_lst = [False] * N
lst = [[] for _ in range(N)]
for _ in range(N + M - 1):
    A, B = map(int, input().split())
    A -= 1
    B -= 1
    lst[A].append(B)
    check_lst[B] = True
# print (lst)

ans_lst = [[-1, 0] for _ in range(N)] #[親, 距離]を要素とするリスト
#根を求める = どこからも辺が伸びていないところ --> check_lst = Falseの場所
n = check_lst.index(False)
ans_lst[n][0] = -1
# print (n)

def dfs(i): #iからの経路を探す
    distance = ans_lst[i][1]
    for j in lst[i]:
        # print (j)
        if distance + 1 > ans_lst[j][1]:#距離が最長となるとき
            ans_lst[j][0] = i
            ans_lst[j][1] = distance + 1
            dfs(j)
    return 

dfs(n)
# print (ans_lst)

# print ('以下答え')
for i, d in ans_lst:
    print (i + 1)


### FIXED CODE ###

import sys
# from heapq import heappop, heappush
from collections import deque
sys.setrecursionlimit(10 ** 9)
input = sys.stdin.readline

N, M = map(int, input().split())
check_lst = [0] * N
lst = [[] for _ in range(N)]
for _ in range(N + M - 1):
    A, B = map(int, input().split())
    A -= 1
    B -= 1
    lst[A].append(B)
    check_lst[B] += 1

n = check_lst.index(0)
ans = [0] * N
que = deque()
que.append(n)
while que:
    v = que.popleft()
    for v2 in lst[v]:
        check_lst[v2] -= 1
        if check_lst[v2] == 0:
            que.append(v2)
            ans[v2] = v + 1
print (*ans, sep = '\n')
### BUGGY CODE ###

N = int(input())
A = list(map(int, input().split()))

if N == 1:
    print(1)
    exit()

def saisho_ko_baisu(A,B):
    # A < B
    x = A*B
    r = B%A
    while r!=0:
        B = A
        A = r
        r = B%A
    return x//A

A.sort(reverse = True)
tmp = saisho_ko_baisu(A[0], A[1])
res = tmp//A[0] + tmp//A[1]
for i in range(2,N):
    if tmp % A[i] != 0:
        new = saisho_ko_baisu(A[i], tmp)
        res *= new//tmp
        tmp = new
    res += tmp // A[i]

print(res % (10**9 + 7))


### FIXED CODE ###

from fractions import gcd

def lcm(a):
    x = a[0]
    for i in range(1, len(a)):
        x = (x * a[i]) // gcd(x, a[i])
    return x

n = int(input())
a = list(map(int, input().split()))

div = 10**9 + 7
lcm_num = lcm(a)
ans = [lcm_num//ai for ai in a]

print(sum(ans)%div)
### BUGGY CODE ###

N = int(input())
P = list(map(int, input().split()))
count = 1
for i in range(1, N):
  if P[i] <= min(P[0:i]):
    count += 1
print(count)


### FIXED CODE ###

N = int(input())
P = list(map(int, input().split()))
count = 1
tmp_min = P[0]
for i in range(1, N):
  if P[i] <= tmp_min:
    count += 1
    tmp_min = P[i]
print(count)
### BUGGY CODE ###

import numpy as np
N = int(input())
A = np.array(list(map(int, input().split())))
K = 60

ans = 0
mod = 10 ** 9 + 7
power = 1

for i in range(K):
    bit = sum(A >> i & 1)
    ans += power * ((bit * (N - bit)) % mod)
    power *= 2
    power %= mod
    ans %= mod

print(ans)

### FIXED CODE ###

import numpy as np
N = int(input())
A = np.array(list(map(int, input().split())))

K = len(bin(np.max(A))) - 2

ans = 0
mod = 10 ** 9 + 7
N %= mod

for i in range(K):
    bit = np.count_nonzero(A >> i & 1) % mod
    ans += 2 ** i * bit * (N - bit)
    ans %= mod
    
print(ans)
### BUGGY CODE ###

k, s = map(int, input().split())
ans = []
for i in range(k+1):
    for j in range(min(k+1,s-i+1)):
        for h in range(min(k+1,s-i-j+1)):
            if i + j + h == s:
                ans.append([i, j, h])
                
print(len(ans))

### FIXED CODE ###

k, s = map(int, input().split())
cnt = 0
for i in range(k+1):
    for j in range(min(k+1,s-i+1)):
        h = s- i- j
        if 0<= h <= k:
            cnt += 1
print(cnt)
### BUGGY CODE ###

import sys
def input(): return sys.stdin.readline().rstrip()

R, C, k = (int(x) for x in input().split())
V = [[0] * (C + 5) for _ in range(R + 5)]
for _ in range(k):
    r, c, v = (int(x) for x in input().split())
    V[r][c] = v

# dp[i][j][3]
dp = [[[0] * 4 for _ in range(C + 5)] for _ in range(R + 5)]
for i in range(R + 3):
    for j in range(C + 3):
        for k in range(4):
            # 行移動
            dp[i + 1][j][0] = max(dp[i + 1][j][0], dp[i][j][k])
            dp[i + 1][j][1] = max(dp[i + 1][j][1], dp[i][j][k] + V[i + 1][j])
            # 列移動
            dp[i][j + 1][k] = max(dp[i][j + 1][k], dp[i][j][k])
            if k < 3:
                dp[i][j + 1][k + 1] = max(dp[i][j + 1][k + 1], dp[i][j][k] + V[i][j + 1])
print(max(dp[R][C]))


### FIXED CODE ###

import sys
def input(): return sys.stdin.readline().rstrip()

R, C, k = (int(x) for x in input().split())
V = [[0] * (C + 5) for _ in range(R + 5)]
for _ in range(k):
    r, c, v = (int(x) for x in input().split())
    V[r][c] = v

# dp[3][i][j]
dp = [[[0] * (C + 5) for _ in range(R + 5)] for _ in range(4)]
for i in range(R + 3):
    for j in range(C + 3):
        for k in range(4):
            # 行移動
            dp[0][i + 1][j] = max(dp[0][i + 1][j], dp[k][i][j])
            dp[1][i + 1][j] = max(dp[1][i + 1][j], dp[k][i][j] + V[i + 1][j])
            # 列移動
            dp[k][i][j + 1] = max(dp[k][i][j + 1], dp[k][i][j])
            if k < 3:
                dp[k + 1][i][j + 1] = max(dp[k + 1][i][j + 1], dp[k][i][j] + V[i][j + 1])
print(max(dp[k][R][C] for k in range(4)))
### BUGGY CODE ###

n = int(input())
integers = list(map(int, input().split()))

max_moves = 0
moves = 0
for i in range(n-1):
    for k in range(i, n-1):
        if integers[k] >= integers[k+1]:
            moves += 1
        else:
            break
    if max_moves < moves:
        max_moves = moves
    moves = 0
    if max_moves > n-i-1:
        break
print(max_moves)


### FIXED CODE ###

n = int(input())
integers = list(map(int, input().split()))

max_moves = 0
moves = 0
for i in range(n-1):
    if integers[i] >= integers[i+1]:
        moves += 1
    else:
        moves = 0
    if max_moves < moves:
        max_moves = moves
print(max_moves)
### BUGGY CODE ###

from collections import defaultdict
N = int(input())
A = list(map(int, input().split()))
mod = 10 ** 9 + 7

d = defaultdict(int)

pf = []
for a in A:
    res = []
    for i in range(2, int(a ** 0.5) + 1):
        if a % i == 0:
            cnt = 0
            while a % i == 0:
                cnt += 1
                a //= i
            d[i] = max(d[i], cnt)
            res.append((i, cnt))
    if a != 1:
        d[a] = max(d[a], 1)
        res.append((a, 1))
    pf.append(res)

ans = 0
for i, a in enumerate(A):
    tmpD = d.copy()
    for k, v in pf[i]:
        tmpD[k] -= v
    b = 1
    for k, v in tmpD.items():
        if v <= 0:
            continue
        b *= pow(k, v, mod)
        v %= mod
    ans += b
    ans %= mod

print(ans % mod)


### FIXED CODE ###

from collections import defaultdict
N = int(input())
A = list(map(int, input().split()))
mod = 10 ** 9 + 7

d = defaultdict(int)


def prime_factorization(n):  # 素因数分解
    res = []
    for i in range(2, int(n ** 0.5) + 1):
        if n % i == 0:
            cnt = 0
            while n % i == 0:
                cnt += 1
                n //= i
            res.append((i, cnt))
    if n > 1:
        res.append((n, 1))
    return res


for a in A:
    for i in range(2, int(a ** 0.5) + 1):
        if a % i == 0:
            cnt = 0
            while a % i == 0:
                cnt += 1
                a //= i
            d[i] = max(d[i], cnt)
    if a != 1:
        d[a] = max(d[a], 1)

ans = 0
lcm = 1
for k, v in d.items():
    lcm *= pow(k, v, mod)
    lcm %= mod

for a in A:
    if a == 1:
        ans += lcm
        continue
    l = lcm*pow(a, mod-2, mod)
    ans += l
    ans %= mod

print(ans % mod)
### BUGGY CODE ###

import sys
input=sys.stdin.readline   
sys.setrecursionlimit(100000000)
from functools import lru_cache
INF = 1000000000
MOD = 10**9+7

def main():
    n=int(input())
    s=input()

    dp=[[0]*(1+n) for _ in range(n)]
    for i in range(n-1):
        for j in range(i+1,n):
            if s[i]==s[j]:
                dp[i+1][j+1]=min(dp[i][j]+1,j-i)          
    
    ans=0
    for i in range(n+1):
        for j in range(i+1,n+1):
            ans=max(ans,dp[i][j])
    print(ans)

if __name__=='__main__':
    main()

### FIXED CODE ###

import sys
input=sys.stdin.readline   
sys.setrecursionlimit(100000000)
from functools import lru_cache
INF = 1000000000
MOD = 10**9+7

def main():
    n=int(input())
    s=input()

    dp=[[0]*(1+n) for _ in range(n)]
    for i in range(n-1):
        for j in range(i+1,n):
            if s[i]==s[j]:
                dp[i+1][j+1]=min(dp[i][j]+1,j-i)          
    
    ans=0
    for i in range(n+1):
        for j in range(i+1,n+1):
            ans=max(ans,dp[i][j])
    print(ans)

if __name__=='__main__':
    main()
### BUGGY CODE ###

#!/usr/bin/env python3
def main():
    from collections import deque

    N, M, K = map(int, input().split())
    friends = [set() for _ in range(N + 1)]
    for _ in range(M):
        a, b = map(int, input().split())
        friends[a].add(b)
        friends[b].add(a)
    blocks = [set() for _ in range(N + 1)]
    for _ in range(K):
        c, d = map(int, input().split())
        blocks[c].add(d)
        blocks[d].add(c)

    friends_chain = []
    seen = [-1] * (N + 1)
    cnt = 0
    for person in range(1, N + 1):
        if seen[person] != -1:
            continue
        q = deque([person])
        friends_chain.append(set(q))
        while q:
            now = q.pop()
            seen[now] = cnt
            for next in friends[now]:
                if seen[next] != -1:
                    continue
                friends_chain[-1].add(next)
                q.append(next)
        cnt += 1

    ans = [0] * (N + 1)
    for person in range(1, N + 1):
        res = friends_chain[seen[person]]
        tmp_ans = len(res) - len(friends[person]) - 1
        for block in blocks[person]:
            tmp_ans -= 1 if block in res else 0
        ans[person] = (tmp_ans)
    print(*ans[1:], sep=' ')


if __name__ == '__main__':
    main()


### FIXED CODE ###

#!/usr/bin/env python3
def main():
    from collections import deque

    N, M, K = map(int, input().split())
    friends = [set() for _ in range(N + 1)]
    for _ in range(M):
        a, b = map(int, input().split())
        friends[a].add(b)
        friends[b].add(a)
    blocks = [set() for _ in range(N + 1)]
    for _ in range(K):
        c, d = map(int, input().split())
        blocks[c].add(d)
        blocks[d].add(c)

    friends_chain = []
    seen = [-1] * (N + 1)
    cnt = 0
    for person in range(1, N + 1):
        if seen[person] != -1:
            continue
        q = deque([person])
        friends_chain.append(set(q))
        while q:
            now = q.pop()
            seen[now] = cnt
            for next in friends[now]:
                if seen[next] != -1:
                    continue
                friends_chain[-1].add(next)
                q.append(next)
        cnt += 1

    for person in range(1, N + 1):
        res = friends_chain[seen[person]]
        tmp_ans = len(res) - len(friends[person]) - 1
        for block in blocks[person]:
            tmp_ans -= 1 if block in res else 0
        print(tmp_ans, end=' ')


if __name__ == '__main__':
    main()
### BUGGY CODE ###

H=int(input())
from collections import deque
stack=deque([H])
ans=0
while stack:
    ans+=1
    x=stack.pop()
    if x>1:
        stack.append(x//2)
        stack.append(x//2)
    else:
        continue
print(ans)

### FIXED CODE ###

H=int(input())
counter=0
while H>1:
    H=H//2
    counter+=1
ans=0
for i in range(counter+1):
    ans+=2**i
print(ans)
### BUGGY CODE ###

N=int(input())
P=list(map(int,input().split()))
count = 0
kouho=[]

for i in range(N):
    if P[i]<=min(P[:i+1]):
        count += 1
print(count)

### FIXED CODE ###

import sys
input = sys.stdin.readline
N=int(input())
P=list(map(int,input().split()))
count = 0
saisyouti = P[0]
for i in range(N):
    if P[i]<=saisyouti:
        count += 1
        saisyouti=P[i]
print(count)
### BUGGY CODE ###

N=int(input())
A=list(map(int,input().split()))
Q=int(input())

trans=[[] for _ in range(Q)]
for i in range(Q):
    B,C=map(int,input().split())
    trans[i].append(B)
    trans[i].append(C)

S=0
#まずはじめの合計求める

num=[0]
#これに数の出現回数をプロットする
for i in range(1,10**5+1):
    cnt=A.count(i)
    num.append(cnt)
    if cnt!=0:
        S+=cnt*i
        

for i in range(Q):
    B=trans[i][0]
    C=trans[i][1]
    change=num[B]*(C-B)
    num[C]+=num[B]
    num[B]-=num[B]
    S+=change
    print(S)

### FIXED CODE ###

N = int(input())
A = list(map(int,input().split()))
Q = int(input())
BC = []
for i in range(Q):
    BC.append(list(map(int,input().split())))

num = [0]*(10**5+1)

S = []
 
#1 iterlation
S.append(sum(A))
for i in range(N):
    num[A[i]]+=1

    
for j in range(Q):
    if num[BC[j][0]] != 0:
        #Bに当たる交換するものがある時
        B = BC[j][0]
        C = BC[j][1]
        S.append(S[-1] + (C - B)*num[B] )
        #S[-1]で合計の一番最新のもの
        dammy = num[B]
        num[B] = 0
        num[C] += dammy
 
    else:
        B = BC[j][0]
        C = BC[j][1]
        S.append(S[-1])

        
for i in range(1,Q+1):
    print(S[i])
### BUGGY CODE ###

import sys

n=0
m=0
id_list=[]

def calculate(x):
  _x = x +1
  is_passed = True
  for id_list_index in range(0, m):
    if not((_x >= id_list[id_list_index][0]) and (_x <= id_list[id_list_index][1])) :
      is_passed = False

  return is_passed
  
  
is_arg_ok = False
try:
  n, m  = map(int, input().split())
  for i in range(0, m):
    gate_min, gate_max = map(int, input().split())
    id_list.append([gate_min, gate_max])
  is_arg_ok = True
  
except:
  print('arg error')
  sys.exit(1)


result = len(list(filter(lambda n: calculate(n), range(0, n))))
print(result)
sys.exit(0)



### FIXED CODE ###

import sys
n=0
m=0

n, m  = map(int, input().split())
_min, _max  = map(int, input().split())
for i in range(1, m):
  gate_min, gate_max = map(int, input().split())
  if (_max > gate_max):
    _max = gate_max
   
  if _min < gate_min:
    _min = gate_min
 
result_list = list(filter(lambda x : (_min <= x) and (x <= _max), range(1, n+1)))
result = len(result_list)

print(result)
sys.exit(0)
### BUGGY CODE ###

def MAP(): return map(int,input().split())

H,W = MAP()
lst = [list(input()) for _ in range(H)]
ans=0
for i in range(H):
    for j in range(W):
        tmp=0
        if lst[i][j]=="#":
            continue
        #yoko
        for k in lst[i][j:]:
            if k=="#":
                break
            tmp+=1
        for k in range(j-1,-1,-1):
            if lst[i][k]=="#":
                break
            tmp+=1
        #tate
        for k in range(i,H):
            if lst[k][j]=="#":
                break
            tmp+=1
        for k in range(i-1,-1,-1):
            if lst[k][j]=="#":
                break
            tmp+=1
        ans = max(ans,tmp-1)

print(ans)

### FIXED CODE ###

def MAP(): return map(int,input().split())

H,W = MAP()
lst = [list(input()) for _ in range(H)]
L = [[0 for _ in range(W)] for _ in range(H)]
R = [[0 for _ in range(W)] for _ in range(H)]
D = [[0 for _ in range(W)] for _ in range(H)]
U = [[0 for _ in range(W)] for _ in range(H)]
for i in range(H):
    for j in range(W):
        #Left
        if lst[i][j]==".":
            L[i][j] = L[i][j-1]+1
        #Up
            U[i][j] = U[i-1][j]+1
        #Right
        if lst[i][-(j+1)]==".":
            R[i][-(j+1)] = R[i][-j]+1
        #Down
        if lst[-(i+1)][j]==".":
            D[-(i+1)][j] = D[-i][j]+1
ans=0
for i in range(H):
    for j in range(W):
        ans = max(ans,L[i][j]+R[i][j]+U[i][j]+D[i][j]-3)

print(ans)
### BUGGY CODE ###

N = int(input())
t = list(map(int,input().split()))
v = list(map(int,input().split()))
T = sum(t)*2
vt = [min(i/2,(T-i)/2) for i in range(T+1)]
ts = 0
te = 0
for i in range(N):
    te += t[i]*2
    for j in range(T+1):
        vt[j] = min(vt[j],v[i]+max(0,-(j-ts)/2,(j-te)/2))
    ts = te
print(sum(vt)/2)

### FIXED CODE ###

N = int(input())
t = list(map(int,input().split()))
v = list(map(int,input().split()))
T = sum(t)*2
vt = [min(i/2,(T-i)/2) for i in range(T+1)]
ts = 0
te = 0
for i in range(N):
    te += t[i]*2
    for j in range(T+1):
        vt[j] = min(vt[j],v[i]+max(0,-(j-ts)/2,(j-te)/2))
    ts = te
print(sum(vt)/2)
### BUGGY CODE ###

import sys
import numpy as np
input = sys.stdin.readline
 
S = input().strip()
l = len(S)
dp = [[0 for _ in range(2019)] for i in range(l)]
dp = np.zeros((l, 2019), dtype=int)
for i in range(l):
    s = int(S[i])
    for j in range(2019):
        k = (10 * j + s) % 2019
        dp[i][k] = dp[i-1][j]
    dp[i][s] += 1
 
print(dp[:, 0].sum())

### FIXED CODE ###

import sys
input = sys.stdin.readline

S = input().strip()
l = len(S)
dic = {0:[-1]}
ans = 0
base = 1
mod = 0
for i in range(0, l):
    base = (10 * base) % 2019
    s = base * int(S[l-1-i]) + mod
    mod = s % 2019
    if mod in dic:
        dic[mod].append(i)
    else:
        dic[mod] = [i]

for key, val in dic.items():
    v_len = len(val)
    ans += (v_len * (v_len -1))// 2

print(ans)
### BUGGY CODE ###


N, K = map(int,input().split())
#abstract = abs(N - K)

while abs(N - K) < N:
  N = abs(N - K)

print(N)
  

### FIXED CODE ###

N, K = map(int,input().split())

print(min(N % K, K - (N % K)))
### BUGGY CODE ###

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

a = int(m/n)

li = []
for i in range(1,a+1):
    if m % i == 0:
        li.append(i)
print(li[len(li)-1])

### FIXED CODE ###

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

def yakusuu(n,m):
    for i in range(int(m/n),0,-1):
        if m % i == 0:
            print(i)
            break

yakusuu(n,m)
### BUGGY CODE ###

n = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
c = list(map(int,input().split()))

adic = {}
bdic = {}
cdic = {}


setabc = list(sorted(list(set(a) | set(b) | set(c))))

setdict = {}
for i in range(len(setabc)):
    setdict.update({setabc[i]:i})
    

for i in range(len(a)):
    if setdict[a[i]] in adic:
        adic[setdict[a[i]]] =  adic[setdict[a[i]]] + 1 
    else:
        adic.update({setdict[a[i]]:1})

for i in range(len(b)):
    if setdict[b[i]] in bdic:
        bdic[setdict[b[i]]] =  bdic[setdict[b[i]]] + 1 
    else:
        bdic.update({setdict[b[i]]:1})

for i in range(len(c)):
    if setdict[c[i]] in cdic:
        cdic[setdict[c[i]]] =  cdic[setdict[c[i]]] + 1 
    else:
        cdic.update({setdict[c[i]]:1})

        
        
summer = 0
for i in adic.keys():
    for j in bdic.keys():
        for k in cdic.keys():
            if i< j< k:
                summer = summer + adic[i] * bdic[j] * cdic[k] 
                
print(summer)
                
    
            

### FIXED CODE ###

N = int(input())
a = list(map(int,input().split(" ")))
b = list(map(int,input().split(" ")))
c = list(map(int,input().split(" ")))
#アルゴリズムわからないけどN log N?
a.sort()
b.sort()
c.sort()
 
#O(N)?
i,j,k = 0,0,0
ans = 0
while j < N:
  while i < N and a[i]<b[j] :
    i += 1
  while k < N and c[k]<=b[j]:
    k += 1
  ans += i * (N - k)
  j += 1
 

print(ans)
### BUGGY CODE ###

def go():
    h, w, m = map(int, input().split(" "))
    r, c = {},{}
    d = []
    r_max,c_max=0,0
    u,v=[],[]
    for i in range(m):
        x, y = map(int, input().split(" "))
        if (x - 1) in r.keys():
            r[x - 1] += 1
        else:
            r[x - 1] = 1
        if r[x - 1] > r_max:
            r_max = r[x - 1]
            u=[x-1]
        elif r[x-1]==r_max:
            u.append(x-1)
        if (y - 1) in c.keys():
            c[y - 1] += 1
        else:
            c[y - 1] = 1
        if c[y - 1] > c_max:
            c_max = c[y - 1]
            v=[y-1]
        elif c[y-1]==c_max:
            v.append((y-1))
        d.append((x-1,y-1))

    if r_max==0:
        print(c_max)
    elif c_max==0:
        print(r_max)
    else:
        s=r_max+c_max-1
        for j in u:
            for k in v:
                if (j,k) not in d:
                    s+=1
                    print(s)
                    return
        print(s)

go()

### FIXED CODE ###

h,w,m= map(int,input().split(" "))
ys, xs=[0 for i in range(h)],[0 for j in range(w)]
ms=set()
for i in range(m):
    y,x= map(lambda x: int(x)-1,input().split(" "))
    ys[y]+=1
    xs[x]+=1
    ms.add((y,x))
y_max,x_max= max(ys),max(xs)
largest_ys, largest_xs=[],[]
for i in range(h):
    if ys[i]==y_max:
        largest_ys.append(i)
for i in range(w):
    if xs[i]==x_max:
        largest_xs.append(i)
ans=y_max+x_max-1
for i in largest_ys:
    for j in largest_xs:
        if (i,j) not in ms:
            print(ans+1)
            exit()
print(ans)
### BUGGY CODE ###

n,k = map(int,input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
a.sort()
b.sort(reverse=True)
#print(a)
#print(b)
c = []
for i in range(n):
  c.append([-a[i]*b[i],b[i]])
#print(c)
import heapq
heapq.heapify(c)
for _ in range(k):
  now = heapq.heappop(c)
  if now[0] == 0:
    heapq.heappush(c,now)
    break
  heapq.heappush(c, [now[0]+now[1],now[1]] )
#print(c)
ans = 0
for i in range(n):
  if ans > c[i][0]:
    ans = c[i][0]
print(-1*ans)

### FIXED CODE ###

n,k = map(int,input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
a.sort()
b.sort(reverse=True)
#print(a)
#print(b)
big = 44
stand = 2 ** big
width = 2 ** (big-1)
if sum(a) <= k:
  print(0)
else:
  while True:
    tmp = []
    for i in range(n):
       tmp.append(max(0,a[i]-stand//b[i]))
    if width == 0:
      if sum(tmp) <= k:
        print(stand)
      else:
        print(stand+1)
      break
    if sum(tmp) <= k:
      stand -= width
      width //= 2
    else:
      stand += width
      width //= 2
    #print(stand,tmp)
### BUGGY CODE ###

N = int(input())
S = input()
ans = 0
for i in range(0, N-3):
    for j in range(i+1, N-1):
        I = S[i]
        J = S[j]
        if I != J:
            color = ['R', 'G', 'B']
            color.remove(I)
            color.remove(J)
            r = color[0]
            ans += S[j+1:].count(r)
            try:
                if S[j+(j-i)] == r:
                    ans -= 1
            except IndexError:
                pass
print(ans)


### FIXED CODE ###

N = int(input())
S = input()
r = S.count('R')
g = S.count('G')
b = S.count('B')
ans = r*g*b

for i in range(N-2):
    for j in range(i+1, N):
        k = j+(j-i)
        if k > (N-1):
            break
        if S[i] != S[j] != S[k] != S[i]:
            ans -= 1
print(ans)
### BUGGY CODE ###

import copy

N = int(input())
li = [int(input()) for i in range(N)]

for index, i in enumerate(li):
  tmp = copy.copy(li)

  ans = max(tmp)

  if ans == tmp[index]:
    tmp.pop(index)
    print(max(tmp))
  else:
    print(ans)

### FIXED CODE ###

N = int(input())
li = []
for i in range(N):
  s = int(input())
  li.append(s)
  
new = sorted(li, reverse=True)

s = max(li)
for index, i in enumerate(li):
  if s == li[index]:
    print(new[1])
  else:
    print(new[0])