from sys import stdin, stdout input = lambda: stdin.readline() write = stdout.write def longest(seq): max_count = 0 prev_char = None for current in seq: if current == 'x': prev_char = 'x' continue if prev_char != current: count = 1 else: count += 1 if count > max_count: max_count = count prev_char = current return max_count def main(): D = int(input()) C = stdin.read().splitlines() c = ['x'] * 14 + list(C[0]) + list(C[1]) + ['x'] * 14 gw = longest(c) if not D: print(gw) return for i in range(56 - D): s = ''.join(c[i:i+D]).split('o') n = sum(map(bool, s)) if n == 1: c_ = c[:] c_[i:i+D] = ['o'] * D gw = max(gw, longest(c_)) print(gw) main()