import java.util.*; public class Main { public static void main (String[] args) { Scanner sc = new Scanner(System.in); int d = sc.nextInt(); boolean[] days = new boolean[14]; char[] first = sc.next().toCharArray(); for (int i = 0; i < 7; i++) { days[i] = (first[i] == 'o'); } char[] second = sc.next().toCharArray(); for (int i = 0; i < 7; i++) { days[i + 7] = (second[i] == 'o'); } int max = getLength(days); for (int i = 0; i < 14; i++) { boolean[] tmp = (boolean[])(days.clone()); for (int j = 0; j < d && i + j < 14 && !tmp[i + j]; j++) { tmp[i + j] = true; } max = Math.max(max, getLength(tmp)); } System.out.println(max); } static int getLength(boolean[] days) { int max = 0; int length = 0; for (boolean b : days) { if (b) { length++; max = Math.max(max, length); } else { length = 0; } } return max; } }