// Arup Guha
// 4/8/2020
// Solution to 2020 March Bronze USACO Problem: Social Distancing I

import java.util.*;
import java.io.*;

public class socdist1 {
	
	public static int n;
	public static ArrayList<Integer> locs;
	
	public static void main(String[] args) throws Exception {
		
		// Get input - just store where cows are.
		Scanner stdin = new Scanner(new File("socdist1.in"));
		n = stdin.nextInt();
		String s = stdin.next();
		locs = new ArrayList<Integer>();
		for (int i=0; i<s.length(); i++)
			if (s.charAt(i) == '1') 
				locs.add(i);
			
		// Be careful setting low and high for binary search.
		int low = 1, high = n-1;
		
		// Answer could never be higher than the current gap between two cows.
		for (int i=1; i<locs.size(); i++) high = Math.min(locs.get(i)-locs.get(i-1), high);
				
		// Now, binary search the result.
		while (low < high) {
			int mid = (low+high+1)/2;
			if (canDo(mid))
				low = mid;
			else
				high = mid-1;
		}
			
		// Output result.
		PrintWriter out = new PrintWriter(new FileWriter("socdist1.out"));
		out.println(low);
		out.close();		
		stdin.close();
	}
	
	// Returns true iff we can place 2 cows without getting any cows closer than d.
	public static boolean canDo(int d) {
	
		// Base case so I don't worry about AOOB.
		if (locs.size() == 0) return d < n;
	
		// See how many I can place in the beginning and end.
		int placed = locs.get(0)/d + (n-1-locs.get(locs.size()-1))/d;
		
		// Try everything in the middle.
		for (int i=0; i<locs.size()-1; i++) 
			placed += Math.max(0,((locs.get(i+1) - locs.get(i))/d - 1));
		
		// I win!
		return placed >= 2;
	}
}