import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines import numpy as np S = np.array(list(read().decode('utf-8').rstrip()),'U1') L = len(S) INF = 10 ** 9 left_c = np.full(L,-INF,np.int32) left_c[1:] = np.where(S[:-1] == 'c',np.arange(L-1),-INF) np.maximum.accumulate(left_c,out=left_c) L = len(S) right_w = np.full(L,INF,np.int32) right_w[:-1] = np.where(S[1:] == 'w',np.arange(1,L),INF) right_w = np.minimum.accumulate(right_w[::-1])[::-1] x = right_w - left_c + 1 x[S!='w'] = INF answer = x.min() if answer > L: answer = -1 print(answer)