S = gets.chomp N = S.size M = N / 2 if S != S.reverse puts N exit end if S.size == 1 puts -1 exit end counter = Hash.new(0) M.times do |i| s = S[i] counter[s] += 1 end if N.even? if counter.size == 1 puts 0 else puts N - 2 end else if counter.size == 1 puts -1 else puts N - 2 end end