public class Main{
  public void run(java.io.InputStream in, java.io.PrintStream out){
    java.util.Scanner sc = new java.util.Scanner(in);
/*answer*/
    int n;
    n = sc.nextInt();

    if(n <= 9){
      System.out.println(n);
    }else if(n == 10){
      System.out.println(9);
    }else if(n <= 16){
      System.out.println(11);
    }else if(n <= 27){
      System.out.println(22);
    }else if(n <= 38){
      System.out.println(33);
    }else if(n <= 49){
      System.out.println(44);
    }else if(n <= 60){
      System.out.println(55);
    }else if(n <= 71){
      System.out.println(66);
    }else if(n <= 82){
      System.out.println(77);
    }else if(n <= 93){
      System.out.println(88);
    }else if(n <= 100){
      System.out.println(99);
    }else if(n <= 106){
      System.out.println(101);
    }else if(n <= 116){
      System.out.println(111);
    }else if(n <= 126){
      System.out.println(121);
    }else if(n <= 136){
      System.out.println(131);
    }else if(n <= 146){
      System.out.println(141);
    }else if(n <= 156){
      System.out.println(151);
    }else if(n <= 166){
      System.out.println(161);
    }else if(n <= 176){
      System.out.println(171);
    }else if(n <= 186){
      System.out.println(181);
    }else if(n <= 196){
      System.out.println(191);
    }else if(n <= 207){
      System.out.println(202);
    }else if(n <= 217){
      System.out.println(212);
    }else if(n <= 227){
      System.out.println(222);
    }else if(n <= 237){
      System.out.println(232);
    }else if(n <= 247){
      System.out.println(242);
    }else if(n <= 257){
      System.out.println(252);
    }else if(n <= 267){
      System.out.println(262);
    }else if(n <= 277){
      System.out.println(272);
    }else if(n <= 287){
      System.out.println(282);
    }else if(n <= 297){
      System.out.println(292);
    }else if(n <= 308){
      System.out.println(303);
    }else if(n <= 318){
      System.out.println(313);
    }else if(n <= 328){
      System.out.println(323);
    }else if(n <= 338){
      System.out.println(333);
    }else if(n <= 348){
      System.out.println(343);
    }else if(n <= 358){
      System.out.println(353);
    }else if(n <= 368){
      System.out.println(363);
    }else if(n <= 378){
      System.out.println(373);
    }else if(n <= 388){
      System.out.println(383);
    }else if(n <= 398){
      System.out.println(393);
    }else if(n <= 409){
      System.out.println(404);
    }else if(n <= 419){
      System.out.println(414);
    }else if(n <= 429){
      System.out.println(424);
    }else if(n <= 439){
      System.out.println(434);
    }else if(n <= 449){
      System.out.println(444);
    }else if(n <= 459){
      System.out.println(454);
    }else if(n <= 469){
      System.out.println(464);
    }else if(n <= 479){
      System.out.println(474);
    }else if(n <= 489){
      System.out.println(484);
    }else if(n <= 499){
      System.out.println(494);
    }else if(n <= 510){
      System.out.println(505);
    }else if(n <= 520){
      System.out.println(515);
    }else if(n <= 530){
      System.out.println(525);
    }else if(n <= 540){
      System.out.println(535);
    }else if(n <= 550){
      System.out.println(545);
    }else if(n <= 560){
      System.out.println(555);
    }else if(n <= 570){
      System.out.println(565);
    }else if(n <= 580){
      System.out.println(575);
    }else if(n <= 590){
      System.out.println(585);
    }else if(n <= 600){
      System.out.println(595);
    }else if(n <= 611){
      System.out.println(606);
    }else if(n <= 621){
      System.out.println(616);
    }else if(n <= 631){
      System.out.println(626);
    }else if(n <= 641){
      System.out.println(636);
    }else if(n <= 651){
      System.out.println(646);
    }else if(n <= 661){
      System.out.println(656);
    }else if(n <= 671){
      System.out.println(666);
    }else if(n <= 681){
      System.out.println(676);
    }else if(n <= 691){
      System.out.println(686);
    }else if(n <= 701){
      System.out.println(696);
    }else if(n <= 712){
      System.out.println(707);
    }else if(n <= 722){
      System.out.println(717);
    }else if(n <= 732){
      System.out.println(727);
    }else if(n <= 742){
      System.out.println(737);
    }else if(n <= 752){
      System.out.println(747);
    }else if(n <= 762){
      System.out.println(757);
    }else if(n <= 772){
      System.out.println(767);
    }else if(n <= 782){
      System.out.println(777);
    }else if(n <= 792){
      System.out.println(787);
    }else if(n <= 802){
      System.out.println(797);
    }else if(n <= 813){
      System.out.println(808);
    }else if(n <= 823){
      System.out.println(818);
    }else if(n <= 833){
      System.out.println(828);
    }else if(n <= 843){
      System.out.println(838);
    }else if(n <= 853){
      System.out.println(848);
    }else if(n <= 863){
      System.out.println(858);
    }else if(n <= 873){
      System.out.println(868);
    }else if(n <= 883){
      System.out.println(878);
    }else if(n <= 893){
      System.out.println(888);
    }else if(n <= 903){
      System.out.println(898);
    }else if(n <= 914){
      System.out.println(909);
    }else if(n <= 924){
      System.out.println(919);
    }else if(n <= 934){
      System.out.println(929);
    }else if(n <= 944){
      System.out.println(939);
    }else if(n <= 954){
      System.out.println(949);
    }else if(n <= 964){
      System.out.println(959);
    }else if(n <= 974){
      System.out.println(969);
    }else if(n <= 984){
      System.out.println(979);
    }else if(n <= 994){
      System.out.println(989);
    }else if(n <= 1000){
      System.out.println(999);
    }else if(n <= 1056){
      System.out.println(1001);
    }else if(n <= 1166){
      System.out.println(1111);
    }else if(n <= 1276){
      System.out.println(1221);
    }else if(n <= 1386){
      System.out.println(1331);
    }else if(n <= 1496){
      System.out.println(1441);
    }else if(n <= 1606){
      System.out.println(1551);
    }else if(n <= 1716){
      System.out.println(1661);
    }else if(n <= 1826){
      System.out.println(1771);
    }else if(n <= 1936){
      System.out.println(1881);
    }else if(n <= 1996){
      System.out.println(1991);
    }else if(n <= 2057){
      System.out.println(2002);
    }else if(n <= 2167){
      System.out.println(2112);
    }else if(n <= 2277){
      System.out.println(2222);
    }else if(n <= 2387){
      System.out.println(2332);
    }else if(n <= 2497){
      System.out.println(2442);
    }else if(n <= 2607){
      System.out.println(2552);
    }else if(n <= 2717){
      System.out.println(2662);
    }else if(n <= 2827){
      System.out.println(2772);
    }else if(n <= 2937){
      System.out.println(2882);
    }else if(n <= 2997){
      System.out.println(2992);
    }else if(n <= 3058){
      System.out.println(3003);
    }else if(n <= 3168){
      System.out.println(3113);
    }else if(n <= 3278){
      System.out.println(3223);
    }else if(n <= 3388){
      System.out.println(3333);
    }else if(n <= 3498){
      System.out.println(3443);
    }else if(n <= 3608){
      System.out.println(3553);
    }else if(n <= 3718){
      System.out.println(3663);
    }else if(n <= 3828){
      System.out.println(3773);
    }else if(n <= 3938){
      System.out.println(3883);
    }else if(n <= 3998){
      System.out.println(3993);
    }else if(n <= 4059){
      System.out.println(4004);
    }else if(n <= 4169){
      System.out.println(4114);
    }else if(n <= 4279){
      System.out.println(4224);
    }else if(n <= 4389){
      System.out.println(4334);
    }else if(n <= 4499){
      System.out.println(4444);
    }else if(n <= 4609){
      System.out.println(4554);
    }else if(n <= 4719){
      System.out.println(4664);
    }else if(n <= 4829){
      System.out.println(4774);
    }else if(n <= 4939){
      System.out.println(4884);
    }else if(n <= 4999){
      System.out.println(4994);
    }else if(n <= 5060){
      System.out.println(5005);
    }else if(n <= 5170){
      System.out.println(5115);
    }else if(n <= 5280){
      System.out.println(5225);
    }else if(n <= 5390){
      System.out.println(5335);
    }else if(n <= 5500){
      System.out.println(5445);
    }else if(n <= 5610){
      System.out.println(5555);
    }else if(n <= 5720){
      System.out.println(5665);
    }else if(n <= 5830){
      System.out.println(5775);
    }else if(n <= 5940){
      System.out.println(5885);
    }else if(n <= 6000){
      System.out.println(5995);
    }else if(n <= 6061){
      System.out.println(6006);
    }else if(n <= 6171){
      System.out.println(6116);
    }else if(n <= 6281){
      System.out.println(6226);
    }else if(n <= 6391){
      System.out.println(6336);
    }else if(n <= 6501){
      System.out.println(6446);
    }else if(n <= 6611){
      System.out.println(6556);
    }else if(n <= 6721){
      System.out.println(6666);
    }else if(n <= 6831){
      System.out.println(6776);
    }else if(n <= 6941){
      System.out.println(6886);
    }else if(n <= 7001){
      System.out.println(6996);
    }else if(n <= 7062){
      System.out.println(7007);
    }else if(n <= 7172){
      System.out.println(7117);
    }else if(n <= 7282){
      System.out.println(7227);
    }else if(n <= 7392){
      System.out.println(7337);
    }else if(n <= 7502){
      System.out.println(7447);
    }else if(n <= 7612){
      System.out.println(7557);
    }else if(n <= 7722){
      System.out.println(7667);
    }else if(n <= 7832){
      System.out.println(7777);
    }else if(n <= 7942){
      System.out.println(7887);
    }else if(n <= 8002){
      System.out.println(7997);
    }else if(n <= 8063){
      System.out.println(8008);
    }else if(n <= 8173){
      System.out.println(8118);
    }else if(n <= 8283){
      System.out.println(8228);
    }else if(n <= 8393){
      System.out.println(8338);
    }else if(n <= 8503){
      System.out.println(8448);
    }else if(n <= 8613){
      System.out.println(8558);
    }else if(n <= 8723){
      System.out.println(8668);
    }else if(n <= 8833){
      System.out.println(8778);
    }else if(n <= 8943){
      System.out.println(8888);
    }else if(n <= 9003){
      System.out.println(8998);
    }else if(n <= 9064){
      System.out.println(9009);
    }else if(n <= 9174){
      System.out.println(9119);
    }else if(n <= 9284){
      System.out.println(9229);
    }else if(n <= 9394){
      System.out.println(9339);
    }else if(n <= 9504){
      System.out.println(9449);
    }else if(n <= 9614){
      System.out.println(9559);
    }else if(n <= 9724){
      System.out.println(9669);
    }else if(n <= 9834){
      System.out.println(9779);
    }else if(n <= 9944){
      System.out.println(9889);
    }else if(n <= 10000){
      System.out.println(9999);
    }



/*fin*/
    sc.close();
  }
  public static void main(String[] args){
    (new Main()).run(System.in, System.out);
  }
}

Measured memory_bytes: 17332