import java.util.ArrayList; import java.util.Collections; import java.util.List; import java.util.Scanner; public class Main { static int []a; static int ans = 0; static List list; static char[]c; public static void main(String[] args) { Scanner scan = new Scanner(System.in); int D = scan.nextInt(); String C1 = scan.next(); String C2 = scan.next(); scan.close(); c = new char[14]; int cnt = 0; list = new ArrayList(); for(int i = 0; i < 7; i++) { char c1 = C1.charAt(i); char c2 = C2.charAt(i); c[i] = c1; c[i + 7] = c2; if(c1 == 'x') { cnt++; list.add(i); } if(c2 == 'x') { cnt++; list.add(i + 1); } } Collections.sort(list); if(cnt <= D) { System.out.println("14"); System.exit(0); } a = new int[cnt]; comb(1, D); System.out.println(ans); } static void comb(int m, int r) { int n = a.length; if(n == r) { return; }else if(n < r){ System.out.println("エラー"); System.exit(0); } if(m <= r) { int k = a[m - 1] + 1; for(int i = k; i <= n - r + m; i++){ a[m] = i; comb(m + 1, r); } } else { char[]b = new char[14]; for(int i = 0; i < 14; i++) { b[i] = c[i]; } for(int i = 1; i <= r; i++) { //System.out.println(a[i]); b[a[i] - 1] = 'o'; } int t = solve(b); if(ans < t) { ans = t; } } } static int solve(char []c) { int k = 0; int max = 0; for(int i = 0; i < 14; i++) { if(c[i] == 'o') { k++; }else { k = 0; } if(max < k) { max = k; } } return max; } }