f (n:ns) (0,b) = ns!!(b-1):take (b-1) ns++n:drop b ns f (n:ns) (a,b) = n : (f (ns) ((a-1),(b-1))) main=do n<-getLine print$maximum$map (read::String->Integer)$n:map (f n)(concat[[(a,b)|b<-[a+1..length n-1]]|a<-[0..length n-1]])