using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Sockets;

namespace SandboxForAtCoder
{
    public class Program
    {
        // give up.
      
      
      
      
      
      
      
      
      
      
      
      
      
        public static void Main(string[] args)
        {
            var line1 = Console.In.ReadLine();

            var s = line1;


            var zeroCount = s.Count(co => co == '0');
            var oneCount = s.Count(co => co == '1');
            var qCount = s.Count(co => co == '?');

            var diff = Math.Abs(zeroCount - oneCount);


            if (qCount == 0)
            {
                Console.WriteLine(diff);
                return;
            }


            if (diff > qCount)
            {
                var a = diff - qCount;

                Console.WriteLine(a);
                return;
            }
            else
            {
                if (qCount % 2 == 0)
                {
                    // ? even

                    if (zeroCount == 0 || oneCount == 0)
                    {
                        Console.WriteLine(2);
                        return;
                    }
                    else
                    {
                        Console.WriteLine(1);
                        return;
                    }

                }
                else
                {
                    // ? odd 

                    Console.WriteLine(1);
                    return;
                }
            }
        }
    }
}