max = gets.chomp.to_i dividor = 10**9+1 cnt=0 idx = 1 num = idx*dividor while num <= max s = num.to_s slicer = s.size % 2 ? num/2 : num/2+1 a = s.slice(0,slicer) b = s.reverse.slice(0,slicer) cnt+=1 if a==b num = (idx+=1)*dividor end puts cnt.to_s