// Slower C++ solution:
#include <vector> 

#include <list> 

#include <map> 

#include <set> 

#include <deque> 

#include <queue> 

#include <stack> 

#include <bitset> 

#include <algorithm> 

#include <functional> 

#include <numeric> 

#include <utility> 

#include <sstream> 

#include <iostream> 

#include <iomanip> 

#include <cstdio> 

#include <cmath> 

#include <cstdlib> 

#include <cctype> 

#include <string> 

#include <cstring> 

#include <ctime> 

using namespace std;



#define _int64 long long



char s[600000];

int dp[600000][3];

vector<int> a;



int main()

{

  int i,j,n,cnt,tmp;

  cin >> n >> s;

  cnt=0;

  a.clear();

  for (i=0;i<n;i++)

  {

    if (s[i]=='1') cnt++;

    else

    {

      if (cnt>0) a.push_back(cnt);

      a.push_back(0);

      cnt=0;

    }

  }

  if (cnt>0) a.push_back(cnt);

  memset(dp,-1,sizeof(dp));

  dp[0][0]=0;

  for (i=0;i<a.size();i++)

  {

    for (j=0;j<3;j++)

      if (dp[i][j]!=-1)

      {

        if (dp[i+1][0]<dp[i][j])

          dp[i+1][0]=dp[i][j];

        if ((i+2<a.size())&&(a[i]>0)&&(a[i+1]==0)&&(a[i+2]>0))

        {

          if (j==0)

          {

            tmp=dp[i][j]+a[i]+1-1;

            if (a[i+2]>1)

            {

              if (tmp>dp[i+2][1]) dp[i+2][1]=tmp;

            }

            else

            {

              if (tmp>dp[i+3][0]) dp[i+3][0]=tmp;

            }

            tmp=dp[i][j]+1+a[i+2]-1;

            if (tmp>dp[i+3][0]) dp[i+3][0]=tmp;

            if (a[i+2]>1)

            {

              tmp=dp[i][j]+1+a[i+2]-1-1;

              if (tmp>dp[i+2][2]) dp[i+2][2]=tmp;

            }

          }

          if (j==1)

          {

            tmp=dp[i][j]+a[i]-1+1-1;

            if (a[i+2]>1)

            {

              if (tmp>dp[i+2][1]) dp[i+2][1]=tmp;

            }

            else

            {

              if (tmp>dp[i+3][0]) dp[i+3][0]=tmp;

            }

            tmp=dp[i][j]+1+a[i+2]-1;

            if (tmp>dp[i+3][0]) dp[i+3][0]=tmp;

            if (a[i+2]>1)

            {

              tmp=dp[i][j]+1+a[i+2]-1-1;

              if (tmp>dp[i+2][2]) dp[i+2][2]=tmp;

            }

          }

          if (j==2)

          {

            tmp=dp[i][j]+1+1-1;

            if (a[i+2]>1)

            {

              if (tmp>dp[i+2][1]) dp[i+2][1]=tmp;

            }

            else

            {

              if (tmp>dp[i+3][0]) dp[i+3][0]=tmp;

            }

            tmp=dp[i][j]+1+a[i+2]-1;

            if (tmp>dp[i+3][0]) dp[i+3][0]=tmp;

            if (a[i+2]>1)

            {

              tmp=dp[i][j]+1+a[i+2]-1-1;

              if (tmp>dp[i+2][2]) dp[i+2][2]=tmp;

            }

          }

        }

      }

  }

  printf("%d\n",dp[a.size()][0]);

  return 0;

}

// Faster C++ solution for the same problem (measured speedup: 1.402570120858455x):
#include <bits/stdc++.h>

using namespace std;

const int MAXN = 1234567;

char s[MAXN];

int f[MAXN];

int nxt[MAXN],prv[MAXN];

int main()

{

    int n;

    scanf("%d", &n);

    scanf("%s", s);

    memset(f,0,sizeof(f));

    nxt[n] = n;

    for(int i = n-1; i >= 0; --i)

    {

        if(s[i] == '0')

            nxt[i] = i;

        else

            nxt[i] = nxt[i+1];

    }

    for(int i = 0; i < n; ++i)

    {

        if(s[i] == '0')

            prv[i] = i;

        else

            prv[i] = (i==0?-1:prv[i-1]);

    }

    for(int i = 0; i  <= n; ++i)

    {

        if(i >= 3 && s[i-1] == '1' && s[i-2] == '0' && s[i-3] == '1')

        {

            int j = prv[i-3];

            f[i] = max(f[i],f[j+1]+(i-j-3));

            if(j != i-4)

                f[i] = max(f[i],f[j+2]+(i-j-4));

        }

        if(i == n)

            break;

        if(i+3 <= n && s[i] == '1' && s[i+1] == '0' && s[i+2] == '1')

        {

            int j = nxt[i+2];

            f[j] = max(f[j],f[i]+(j-i-2));

            if(j != i+3)

                f[j-1] = max(f[j-1],f[i]+(j-i-3));

        }

        f[i+1] = max(f[i+1],f[i]);

    }

    printf("%d\n",f[n]);

    return 0;

}