def min_operations_to_make_good(s): n = len(s) arr = [int(c) for c in s] changed = set() for i in range(n-1): balance = 0 zero_positions = [] for j in range(i, n): if arr[j] == 0: balance -= 1 zero_positions.append(j) else: balance += 1 if j > i and balance <= 0 and zero_positions: pos = zero_positions[0] zero_positions.pop(0) if pos not in changed: arr[pos] = 1 changed.add(pos) balance += 2 return len(changed) n = int(input()) s = input().strip() print(min_operations_to_make_good(s))