D = int(raw_input()) C = list(raw_input()) + list(raw_input()) count = 0 max_holiday = 0 for i in range(14): if C[i] == "o": count += 1 else: if i + D >= 14: count += 14 - i else: count += D for j in range(i+D,14): if C[j] == "o": count += 1 else: break max_holiday = max(max_holiday, count) count = 0 else: max_holiday = max(max_holiday, count) print max_holiday