import java.util.*; class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int d = sc.nextInt(); boolean[] day = new boolean[42]; char[] in = sc.next().toCharArray(); for(int i = 0; i < 7; i++) { day[14 + i] = (in[i] == 'o')?true:false; } in = sc.next().toCharArray(); for(int i = 0; i < 7; i++) { day[21 + i] = (in[i] == 'o')?true:false; } int max = 0; for(int i = 0; i < 42; i++) { boolean[] cp = Arrays.copyOf(day, day.length); for(int j = 0; j < d; j++) { if(i + j >= cp.length) break; if(cp[i + j]) break; cp[i + j] = true; } for(int j = 0; j < 42; j++) { if(!cp[j]) continue; for(int k = j; k < 42; k++) { if(!cp[k]) { max = Math.max(max, k - j); break; } } } } System.out.println(max); } }