inputed_list = list(input()) res = 1 tmp_list = [] for i in range(len(inputed_list)): tmp_list.clear() for e in inputed_list: tmp_list.append(e) j = 1 length = 1 while True: if i - j < 0: break try: b = tmp_list[i - j] f = tmp_list[i + j] if b == f or (b == 'b' and f == 'd') or (b == 'd' and f == 'b') or ( b == 'p' and f == 'q') or (b == 'q' and f == 'p'): length += 1 res = max(res, length) j += 1 else: tmp_list[i - j] = ' ' tmp_list[i + j] = ' ' j += 1 except: break if res == 1: print(0) else: print(res * 2 - 1)