
import os
import sys
# 请在此输入您的代码
day = int(input())
for i in range(day+1,99999999):
i = str(i)
if int(i[4:6])<=12 and int(i[6:])<=30:
if str(i) == str(i)[::-1]:
print(i)
break
for i in range(day+1,99999999):
i = str(i)
if int(i[4:6])<=12 and int(i[6:])<=30:
if i[0] == i[2] == i[5] ==i[7] and i[1] == i[3] == i[4] == i[6]:
print(i)
break