using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ProgrammingContest
{
    class MainClass
    {
        Scanner sc;
        static void Main(string[] args)
        {
            new MainClass().Solve();
        }

        void Solve()
        {
#if DEBUG
            string backPath = "..";
            char dirSep = System.IO.Path.DirectorySeparatorChar;
            string inFilePath = backPath + dirSep + backPath + dirSep + "in.txt";
            sc = new Scanner(new System.IO.StreamReader(inFilePath));
#else
            sc = new Scanner();
#endif

            const string target = "101";
            int n = sc.NextInt + 2;
            string s = "0" + sc.Next + "0";
            int[] dp = new int[n];
            List<int>[] lists = new List<int>[n].Select(list => new List<int>()).ToArray();
            for (int i = 0; i + 2 < n; i++)
            {
                if (s.Substring(i, 3).Equals(target))
                {
                    int l = i - 1;
                    while (s[l] == '1')
                    {
                        // 01...101
                        // [l, i + 2]
                        l--;
                    }
                    int r = i + 3;
                    while (s[r] == '1')
                    {
                        // 101...10
                        // [i, r]
                        r++;
                    }
                    lists[l + 1].Add(i + 3);    // 01...101
                    lists[l + 2].Add(i + 3);    // 01...101
                    lists[i].Add(r);        // 101...10
                    lists[i].Add(r - 1);        // 101...10
                }
            }
            for (int i = 0; i < n - 1; i++)
            {
                dp[i + 1] = Math.Max(dp[i + 1], dp[i]);
                foreach (int val in lists[i])
                {
                    dp[val] = Math.Max(dp[val], dp[i] + (val - i - 2)); 
                }
            }
            Write(dp.Last());
        }

        void Write(object val)
        {
            Console.WriteLine(val.ToString());
        }
        void Write(string format, params object[] vals)
        {
            Console.WriteLine(format, vals);
        }
    }
    class Scanner
    {
        Queue<String> buffer;
        char[] sep;
        System.IO.TextReader reader;
        public Scanner(System.IO.TextReader reader = null)
        {
            this.buffer = new Queue<string>();
            this.sep = new char[] { ' ' };
            this.reader = (reader ?? Console.In);
        }
        private void CheckBuffer()
        {
            if (this.buffer.Count == 0 && this.reader.Peek() >= 0)
            {
                string[] sreArray = this.reader.ReadLine().Split(this.sep);
                foreach (String elStr in sreArray)
                {
                    this.buffer.Enqueue(elStr);
                }
            }
        }

        public String Next
        {
            get
            {
                this.CheckBuffer();
                return this.buffer.Dequeue();
            }
        }

        public int NextInt
        {
            get
            {
                return int.Parse(this.Next);
            }
        }
        public double NextDouble
        {
            get
            {
                return double.Parse(this.Next);
            }
        }

        public long NextLong
        {
            get
            {
                return long.Parse(this.Next);
            }
        }
        public bool IsEmpty
        {
            get
            {
                this.CheckBuffer();
                return this.buffer.Count == 0;
            }
        }
    }
}


Measured memory_bytes: 55748