import java.util.*; public class Main { public static void main (String[] args) { Scanner sc = new Scanner(System.in); int d = sc.nextInt(); char[][] arrs = new char[2][]; arrs[0] = sc.next().toCharArray(); arrs[1] = sc.next().toCharArray(); boolean[] holidays = new boolean[14]; for (int i = 0; i < 2; i++) { for (int j = 0; j < 7; j++) { holidays[i * 7 + j] = arrs[i][j] == 'o'; } } int max = 0; for (int i = 0; i + d - 1 < 14; i++) { int count = 0; int idx = i - 1; while (idx >= 0 && holidays[idx]) { idx--; count++; } idx = i + d; while (idx < 14 && holidays[idx]) { idx++; count++; } max = Math.max(max, d + count); } System.out.println(max); } }