N,c = input().split()
N = int(N)
c = int(c)
input1,input2 = 0,0
kordinate = []
stala = 0
maxstala = 0
for i in range(N):
    input1,input2 = input().split()
    input1,input2 = int(input1),int(input2)
    kordinate.append([abs(input1%c),abs(input2%c)])
for i in range(N):
    stala = 0
    for j in range(N):
        if kordinate[i][0] == kordinate[j][0] or kordinate[i][1] == kordinate[j][1]:
            stala +=1 
        elif (kordinate[i][0]+kordinate[i][1])%c ==(kordinate[j][0]+kordinate[j][1])%c:
            stala += 1
    maxstala = max(maxstala,stala)
print(maxstala)