import java.awt.geom.Point2D; import java.io.*; import java.math.*; import java.util.*; import java.util.Map.*; class Main { public static void main(String[] args) { //FastScanner sc = new FastScanner(); Scanner sc = new Scanner(System.in); int d = sc.nextInt(); boolean[] day = new boolean[100]; char[] in = sc.next().toCharArray(); for(int i = 0; i < 7; i++) { day[50 + i] = (in[i] == 'o')?true:false; } in = sc.next().toCharArray(); for(int i = 0; i < 7; i++) { day[57 + i] = (in[i] == 'o')?true:false; } int max = 0; for(int i = 0; i < 100; 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 < 100; j++) { if(!cp[j]) continue; for(int k = j; k < 100; k++) { if(!cp[k]) { max = Math.max(max, k - j); break; } } } } System.out.println(max); } static Point crosspointLL(Point a1, Point a2, Point b1, Point b2) { // ベクトルaの長さをd1/d2倍すると直線bに接するようにd1,d2を設定 Point a = a2.subtract(a1); Point b = b2.subtract(b1); double d1 = b.cross(b1.subtract(a1)); double d2 = b.cross(a); if (Math.abs(d1) < EPS && Math.abs(d2) < EPS) return a1; // same line // 同一直線時の線分の交点を考えるなら return intersectsSP(b1,b2,a1) ? a1 : a2; としてはどうか if (Math.abs(d2) < EPS) throw new IllegalArgumentException( "PRECONDITION NOT SATISFIED"); return a1.add(a.multiply(d1 / d2)); } static class Data implements Comparable { static Point pp; Point s; Point t; boolean o; boolean l; double dist; Data(Point s, Point t, boolean o, boolean l) { this.s = s; this.t = t; this.o = o; this.l = l; } @Override public int compareTo(Data o) { if(this.dist < o.dist) return -1; if(this.dist > o.dist) return 1; return 0; } } static double distanceSP(Point a1, Point a2, Point b) { Point r = projection(a1, a2, b); // 投影した点が線分上にあるなら、点pからその点への距離を返せばいい if (intersectsSP(a1, a2, r)) return r.distance(b); return Math.min(b.distance(a1), b.distance(a2)); } static boolean intersectsSP(Point a1, Point a2, Point b) { return ccw(a1, a2, b) == 0; } static Point projection(Point a1, Point a2, Point p) { Point a = a2.subtract(a1); p = p.subtract(a1); double t = a.dot(p) / a.distanceSqr(); // |a||p|cosθ=t|a|^2, a,tが固定でθが動くとき、点pの軌跡は直線 return a1.add(a.multiply(t)); } static class Point extends Point2D.Double implements Comparable { public Point() { } public Point(double x, double y) { super(x, y); // xとyはfinalではないが、このライブラリ関数の一部は変更されないことを前提としているので注意。 } /** 内積 dot(v1,v2)=|v1||v2|cosθ */ double dot(Point p) { return x * p.x + y * p.y; } /** 外積 cross(v1,v2)=|v1||v2|sinθ */ double cross(Point p) { return x * p.y - y * p.x; } double distanceSqr() { return x * x + y * y; } double distance() { return Math.hypot(x, y); } Point add(Point p) { return new Point(x + p.x, y + p.y); } Point multiply(double k) { return new Point(k * x, k * y); } Point multiply(Point p) { // complex mul: (x+yi)*(p.x+p.yi) return new Point(x * p.x - y * p.y, x * p.y + p.x * y); } Point subtract(Point p) { return new Point(x - p.x, y - p.y); } @Override public boolean equals(Object obj) { // この関数はEclipseで生成して座標の比較だけ書き換えればいい if (this == obj) return true; if (obj == null) return false; if (getClass() != obj.getClass()) return false; Point other = (Point) obj; if (!approxEquals(x, other.x)) return false; if (!approxEquals(y, other.y)) return false; return true; } @Override public int compareTo(Point o) { if (!approxEquals(x, o.x)) return (int) Math.signum(x - o.x); if (!approxEquals(y, o.y)) return (int) Math.signum(y - o.y); return 0; } @Override public String toString() { return "(" + x + "," + y + ")"; } } static boolean approxEquals(double a, double b) { return Math.abs(a - b) < EPS; } static final double EPS = 1e-12; static boolean intersectsSS(Point a1, Point a2, Point b1, Point b2) { // 互いの端点が自身の左右に分かれているならtrue return ccw(a1, a2, b1) * ccw(a1, a2, b2) <= 0 && ccw(b1, b2, a1) * ccw(b1, b2, a2) <= 0; } static int ccw(Point a, Point b, Point c) { b = b.subtract(a); c = c.subtract(a); if (b.cross(c) > EPS) return +1; // counter clockwise if (b.cross(c) + EPS < 0) return -1; // clockwise if (b.dot(c) + EPS < 0) return +2; // c--a--b on line and a!=c if (b.distanceSqr() < c.distanceSqr()) return -2; // a--b--c on line or a==b ※基本的にa==bとなるべきでない  return 0; // a--c--b on line or b==c } static class FastScanner { private final InputStream in = System.in; private final byte[] buffer = new byte[1024]; private int ptr = 0; private int buflen = 0; private boolean hasNextByte() { if (ptr < buflen) { return true; }else{ ptr = 0; try { buflen = in.read(buffer); } catch (IOException e) { e.printStackTrace(); } if (buflen <= 0) { return false; } } return true; } private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;} private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;} private void skipUnprintable() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++;} public boolean hasNext() { skipUnprintable(); return hasNextByte();} public String next() { if (!hasNext()) throw new NoSuchElementException(); StringBuilder sb = new StringBuilder(); int b = readByte(); while(isPrintableChar(b)) { sb.appendCodePoint(b); b = readByte(); } return sb.toString(); } public long nextLong() { if (!hasNext()) throw new NoSuchElementException(); long n = 0; boolean minus = false; int b = readByte(); if (b == '-') { minus = true; b = readByte(); } if (b < '0' || '9' < b) { throw new NumberFormatException(); } while(true){ if ('0' <= b && b <= '9') { n *= 10; n += b - '0'; }else if(b == -1 || !isPrintableChar(b)){ return minus ? -n : n; }else{ throw new NumberFormatException(); } b = readByte(); } } public int nextInt() { if (!hasNext()) throw new NoSuchElementException(); int n = 0; boolean minus = false; int b = readByte(); if (b == '-') { minus = true; b = readByte(); } if (b < '0' || '9' < b) { throw new NumberFormatException(); } while(true){ if ('0' <= b && b <= '9') { n *= 10; n += b - '0'; }else if(b == -1 || !isPrintableChar(b)){ return minus ? -n : n; }else{ throw new NumberFormatException(); } b = readByte(); } } } }