import Data.List
f3::[Int]->Bool
f3 (a:b:c:[])
   |a==b && b==c=True
   |otherwise   =False

f2 ::[Int]->Bool
f2 (a:b:c:[])
     |a<=(-2) || b<=(-2) || c<=(-2)=False
     |otherwise           =True

f :: [Int]->[[Int]]
f (a:b:c:[]) =nub $ map sort $ ((a-2):(b-2):c:[]):((a-2):b:(c-2):[]):(a:(b-2):(c-2):[]):((a-1):b:c:[]):(a:(b-1):c:[]):(a:b:(c-1):[]):[]

f4 :: [[Int]] -> [[[Int]]]
f4 []=[]
f4 (x:xs)=(f x):f4 xs

f5 :: Int->[[Int]]->Int
f5 n xs
   |null (filter f3 xs)=f5 (n+1) (nub ( filter f2 (concat (f4 xs))))
   |otherwise=n

main = do
       x<-getLine
       let ys=[sort $ map read (words x)::[Int]]
       putStrLn $ show $ f5 0 ys