import java.util.Scanner;
public class Main{
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
int data = sc.nextInt();//键盘获取年份
huiwen(data);
AB(data);
sc.close();
}
public static void huiwen(int n){
for(int i=n+1;i<89991231;i++)
{
String str1 = i + "";
char[] ch1 = str1.toCharArray();
char a = ch1[0],b = ch1[1],c = ch1[2],d = ch1[3],e = ch1[4],f = ch1[5],g = ch1[6],h = ch1[7];
if(a==h&&b==g&&c==f&&d==e){
System.out.println(ch1);
break;
}
}
}
public static void AB(int n){
for(int i=n+1;i<89991231;i++)
{
String str2 = i + "";
char[] ch2 = str2.toCharArray();
char a = ch2[0],b = ch2[1],c = ch2[2],d = ch2[3],e = ch2[4],f = ch2[5],g = ch2[6],h = ch2[7];
//ABABBABA
if(a==c&&c==f&&f==h&&b==d&&d==e&&e==g)
{
System.out.println(str2);
break;
}
}
}
}