#!/usr/bin/env ruby

class String
  def has_kaibunability?
    [0, 1].include? self.strip.chars.group_by(&:itself).values.map(&:size).reject(&:even?).size
  end
end

s = gets.strip

@hunko = {}
def unko(s)
  @hunko[s.chars.sort.join] ||= if s.has_kaibunability?
    1
  else
    (1..(s.size - 1)).to_a.sort_by { |k| k - s.size / 2 }.map { |sp|
      (unko(s[0..(sp - 1)]) + unko(s[sp..-1])).tap { |k| return 2 if k == 2 }
    }.min
  end
end

puts unko(s)
