#!/usr/bin/env python3

S = list(input())

cnt1 = 0
m_cnt1 = 0
for s in S:
    if s == '1':
        cnt1 += 1
    else:
        cnt1 -= cnt1 > 0
    m_cnt1 = max(m_cnt1, cnt1)

cnt2 = 0
m_cnt2 = 0
for s in S:
    if s == '2':
        cnt2 += 1
    else:
        cnt2 -= cnt2 > 0
    m_cnt2 = max(m_cnt2, cnt2)

print(max(m_cnt1, m_cnt2))