gside = lambda l, r: ((l and r) and len(l) > len(r) and r) or l or r
lsub = lambda jails, u: u.issubset(set(jails[:-1])) and chk(jails[:-1], u)
rsub = lambda jails, u: u.issubset(set(jails[1:])) and chk(jails[1:], u)
bsrch = lambda jails, u: gside(lsub(jails, u), rsub(jails, u)) or jails
chk = lambda j, u: j if set(j) == u and len(j) == len(u) else bsrch(j, u)
sjail = lambda jails: len(chk(jails, set(jails)))
while True:
try:
inp = str(input())
if inp == '':
break
print(sjail(inp.split(' ')))
except (EOFError):
break
Z3NpZGUgPSBsYW1iZGEgbCwgcjogKChsIGFuZCByKSBhbmQgbGVuKGwpID4gbGVuKHIpIGFuZCByKSBvciBsIG9yIHIKbHN1YiAgPSBsYW1iZGEgamFpbHMsIHU6IHUuaXNzdWJzZXQoc2V0KGphaWxzWzotMV0pKSBhbmQgY2hrKGphaWxzWzotMV0sIHUpCnJzdWIgID0gbGFtYmRhIGphaWxzLCB1OiB1Lmlzc3Vic2V0KHNldChqYWlsc1sxOl0pKSBhbmQgY2hrKGphaWxzWzE6XSwgdSkKYnNyY2ggPSBsYW1iZGEgamFpbHMsIHU6IGdzaWRlKGxzdWIoamFpbHMsIHUpLCByc3ViKGphaWxzLCB1KSkgb3IgamFpbHMKY2hrICAgPSBsYW1iZGEgaiwgdTogaiBpZiBzZXQoaikgPT0gdSBhbmQgbGVuKGopID09IGxlbih1KSBlbHNlIGJzcmNoKGosIHUpCnNqYWlsID0gbGFtYmRhIGphaWxzOiBsZW4oY2hrKGphaWxzLCBzZXQoamFpbHMpKSkKd2hpbGUgVHJ1ZToKCXRyeToKCQlpbnAgPSBzdHIoaW5wdXQoKSkKCQlpZiBpbnAgPT0gJyc6CgkJCWJyZWFrCgkJcHJpbnQoc2phaWwoaW5wLnNwbGl0KCcgJykpKQoJZXhjZXB0IChFT0ZFcnJvcik6CgkJYnJlYWs=