output_description: Print the answer.
  
  * * *
input_description: Input is given from Standard Input in the following format:
  
      
      
      N
      s
attempt: import sys
  
  read = sys.stdin.buffer.read
  readline = sys.stdin.buffer.readline
  readlines = sys.stdin.buffer.readlines
  
  N = int(readline())
  S = readline().rstrip().decode("utf-8")
  
  
  def solve_partial(S):
      INF = 10**18
      """
      ・Sは1から始まり、1で終わる
      ・Sは00を含まない
      ・したがって、Sは1,01に分解可能
      ・残る最小個数を調べるdp。これは、1, 101111,111101 の3種を数えることと同じ
      ・a, b0cccc, dddd0e として、「現在の1がどれであるか -> 最小個数」でdp
      ・個数はa,b,eのときに数える
      """
      S = S.replace("01", "2")
      a, b, c, d, e = 1, 1, INF, 0, INF
      for x in S[1:]:
          if x == "1":
              a2 = min(a, c, e) + 1
              c2 = c
              d2 = min(a, c, d, e)
              e2 = INF
          else:
              a2 = min(a, c, e) + 1
              c2 = a
              d2 = min(a, c, e)
              e2 = d + 1
          a, c, d, e = a2, c2, d2, e2
      return len(S) - min(a, c, e)
  
  
  answer = 0
  for x in S.split("00"):
      x = x.strip("0")
      if x:
          answer += solve_partial(x)
  
  print(answer)
  
problem_description: Statement
  
  N cells are arranged in a row. Some of them may contain tokens. You are given
  a string s that consists of `0`s and `1`s. If the i-th character of s is `1`,
  the i-th cell (from left) contains a token. Otherwise, it doesn't contain a
  token.
  
  Snuke wants to perform the following operation as many times as possible. In
  each operation, he chooses three consecutive cells. Let's call the cells X, Y,
  Z from left to right. In order for the operation to be valid, both X and Z
  must contain tokens and Y must not contain a token. Then, he removes these two
  tokens and puts a new token on Y.
  
  How many operations can he perform if he performs operations in the optimal
  way?
samples: [{"input": "7\n    1010101", "output": "2\n    \n\nFor example, he can perform two operations in the following way:\n\n  * Perform an operation on the last three cells. Now the string that represents tokens becomes `1010010`.\n  * Perform an operation on the first three cells. Now the string that represents tokens becomes `0100010`.\n\nNote that the choice of operations matters. For example, if he chooses three\ncells in the middle first, he can perform no more operations.\n\n* * *"}, {"input": "50\n    10101000010011011110001001111110000101010111100110", "output": "10"}]