def sj_raw(jails, unique=None):
unique = unique or set(jails)
if set(jails) == unique and len(jails) == len(unique):
return jails
else:
lsub = unique.issubset(set(jails[:-1])) and sj_raw(jails[:-1], unique)
rsub = unique.issubset(set(jails[1:])) and sj_raw(jails[1:], unique)
if lsub and rsub:
if len(lsub) > len(rsub):
return rsub
else:
return lsub
else:
return lsub or rsub
sjail = lambda jails: len(sj_raw(jails))
while True:
try:
inp = str(input())
if inp == '':
break
print(sjail(inp.split(' ')))
except (EOFError):
break
ZGVmIHNqX3JhdyhqYWlscywgdW5pcXVlPU5vbmUpOgoJdW5pcXVlID0gdW5pcXVlIG9yIHNldChqYWlscykKCWlmIHNldChqYWlscykgPT0gdW5pcXVlIGFuZCBsZW4oamFpbHMpID09IGxlbih1bmlxdWUpOgoJCXJldHVybiBqYWlscwoJZWxzZToKCQlsc3ViID0gdW5pcXVlLmlzc3Vic2V0KHNldChqYWlsc1s6LTFdKSkgYW5kIHNqX3JhdyhqYWlsc1s6LTFdLCB1bmlxdWUpCgkJcnN1YiA9IHVuaXF1ZS5pc3N1YnNldChzZXQoamFpbHNbMTpdKSkgYW5kIHNqX3JhdyhqYWlsc1sxOl0sIHVuaXF1ZSkKCQlpZiBsc3ViIGFuZCByc3ViOgoJCQlpZiBsZW4obHN1YikgPiBsZW4ocnN1Yik6CgkJCQlyZXR1cm4gcnN1YgoJCQllbHNlOgoJCQkJcmV0dXJuIGxzdWIKCQllbHNlOgoJCQlyZXR1cm4gbHN1YiBvciByc3ViCnNqYWlsID0gbGFtYmRhIGphaWxzOiBsZW4oc2pfcmF3KGphaWxzKSkKd2hpbGUgVHJ1ZToKCXRyeToKCQlpbnAgPSBzdHIoaW5wdXQoKSkKCQlpZiBpbnAgPT0gJyc6CgkJCWJyZWFrCgkJcHJpbnQoc2phaWwoaW5wLnNwbGl0KCcgJykpKQoJZXhjZXB0IChFT0ZFcnJvcik6CgkJYnJlYWs=