#include <iostream>
#include<stdlib.h>
using namespace std;
int main()
{
int i,k,num,x=0,r=0,n=0,d=0;
cin>>k;//k are number of test cases
for(i=1;i<=k;i++)
{
cin>>num;
num+=1;
while(num)
{
n=num;
while(num)
{
d=num%10;
r=(r*10)+d;
num=num/10;
}
if(n==r)
{
cout<<n;
exit(1);
}
else
num++;
}
}
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZTxzdGRsaWIuaD4KdXNpbmcgbmFtZXNwYWNlIHN0ZDsKaW50IG1haW4oKSAKewoJaW50IGksayxudW0seD0wLHI9MCxuPTAsZD0wOwoJY2luPj5rOy8vayBhcmUgbnVtYmVyIG9mIHRlc3QgY2FzZXMKCWZvcihpPTE7aTw9aztpKyspCiB7CgkJY2luPj5udW07CgkJIG51bSs9MTsKCQkgd2hpbGUobnVtKQoJewoJCSBuPW51bTsKCQkgd2hpbGUobnVtKQoJCSB7CgkJIAlkPW51bSUxMDsKCQkgCXI9KHIqMTApK2Q7CgkJIAludW09bnVtLzEwOwoJCSB9CgkJIGlmKG49PXIpCgkJIHsKICAgICAgICAgICAgY291dDw8bjsKICAgICAgICAgICAgZXhpdCgxKTsKCQkgfQoJCSBlbHNlCgkJIG51bSsrOwoJfQogfQoJcmV0dXJuIDA7Cn0=