def min_operations(n, s): # For each position, track the excess of 0s over 1s # in the suffix starting at that position suffix_balance = [0] * (n + 1) # Calculate the suffix balance for i in range(n - 1, -1, -1): if s[i] == '0': suffix_balance[i] = suffix_balance[i + 1] + 1 else: # s[i] == '1' suffix_balance[i] = suffix_balance[i + 1] - 1 # Initialize an array to track the minimum operations needed # to make each suffix a good string min_ops = [0] * (n + 1) # Process the string from right to left for i in range(n - 1, -1, -1): if s[i] == '0': # If adding a 0 creates an imbalance, we need to convert it excess = suffix_balance[i] if excess > 0: # We need to convert this 0 to 1 min_ops[i] = min_ops[i + 1] + 1 else: # We can keep this 0 min_ops[i] = min_ops[i + 1] else: # s[i] == '1' # Adding a 1 always helps the balance min_ops[i] = min_ops[i + 1] return min_ops[0] def main(): n = int(input()) s = input().strip() print(min_operations(n, s)) if __name__ == "__main__": main()