#include<iostream>#include<string>usingnamespace std;int month[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};boolisLeap(int y){return(y %4==0&& y %100!=0)|| y %400==0;}
string pin(int y,int m,int d){
string s, s1;
s1 =to_string(y);
s += s1;
s1 =to_string(m);if(s1.size()==1){
s1 ="0"+ s1;}
s += s1;
s1 =to_string(d);if(s1.size()==1){
s1 ="0"+ s1;}
s += s1;return s;}boolhuiwen(int y,int m,int d){
string s =pin(y, m, d);for(int i =0; i <4; i++){if(s[i]!= s[7- i])returnfalse;}returntrue;}boolAB(int y,int m,int d){
string s =pin(y, m, d);int A = s[0];int B = s[1];if(s[2]== A && s[3]== B && s[4]== B && s[5]== A && s[6]== B && s[7]== A){returntrue;}returnfalse;}intmain(){int n;
cin >> n;int y = n /10000, m = n %10000/100, d = n %100;int f1 =0, f2 =0;while(true){
d++;if(isLeap(y))
month[2]=29;else
month[2]=28;if(d > month[m]){
m++;
d =1;}if(m >12){
y++;
m =1;}if(f1 ==0){if(huiwen(y, m, d)){
string s =pin(y, m, d);int time =stoi(s);
cout << time << endl;
f1 =1;}}if(f2 ==0){if(AB(y, m, d)){
string s =pin(y, m, d);int time =stoi(s);
cout << time << endl;
f2 =1;}}if(f1 && f2){break;}}return0;}