import sys

def solve(type, n, m, map):
    currentId = 0
    joins = []
    sizes = []
    lastRow = None
    for row in map:
        iPlot = 0
        lRow = len(row)
        pRow = []
        while iPlot < lRow:
            current = [row[iPlot], None]
            if lastRow is not None and lastRow[iPlot][0] == row[iPlot]:
                current = lastRow[iPlot]
                sizes[current[1]] += 1
            if iPlot > 0 and pRow[iPlot - 1][0] == row[iPlot]:
                if current[1] is None:
                    current = pRow[iPlot - 1]
                    sizes[current[1]] += 1
                elif current[1] != pRow[iPlot-1][1]:
                    sizes[current[1]] += sizes[pRow[iPlot - 1][1]]
                    sizes[pRow[iPlot - 1][1]] = 0
                    pRow[iPlot - 1][1] = current[1]
            if current[1] is None:
                current[1] = currentId
                currentId += 1
                sizes.append(1)
            pRow.append(current)
            iPlot += 1
        lastRow = pRow
    return max(sizes)
    
if __name__ == "__main__":
    type = int(sys.stdin.readline().strip())
    n, m = map(int, sys.stdin.readline().strip().split())
    map = sys.stdin.read().strip().split("\n")
    if type == 1:
        print solve(type, n, m, map)
    else:
        print "3 4\nv"