import java.util.*; import java.io.*; public class Main { public static void main(String[] args) throws Exception { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); int d = Integer.parseInt(br.readLine()); char[] arr = new char[14]; for (int i = 0; i < 2; i++) { char[] line = br.readLine().toCharArray(); for (int j = 0; j < 7; j++) { arr[i * 7 + j] = line[j]; } } int max = 0; for (int i = 0; i < 14; i++) { boolean norm = false; boolean hor = false; int count = 0; int dCount = 0; for (int j = i; j < 14; j++) { if (arr[j] == 'o') { if (norm) { hor = true; } } else { if (hor) { break; } else { norm = true; } dCount++; if (dCount > d) { break; } } count++; } max = Math.max(max, count); } System.out.println(max); } }