m=Hash.new 0
$stdin.each_char.with_index do |c,p|
  m[c]+=1
  if m.values.reduce(:-)==-1
    puts(p+1)
    exit
  end
end
