#include <stdio.h>
#include <stdlib.h>

int main()
{

  int br1=0,br2=0,x,y,nbr=0,d=10,b=1,obrnuto,nbr2=0,max,br=0,brx=0,bry=0,nx,ny;
  do
  {
  printf("Unesi prirodan broj X: ");
  scanf("%d", &x);
  printf("Unesi prirodan broj Y: ");
  scanf("%d", &y);
  }while (x<=0 || y<=0);

  if(x>y)
  {
   max=x;
  }
  else max=y;
do {
    max /= 10;
    br++;
  } while (max != 0);
  nx=x;
  ny=y;
  do {
    nx /= 10;
    brx++;
  } while (nx != 0);
  do {
    ny /= 10;
    bry++;
  } while (ny != 0);

  for(int i=0; i<br; i++ )
  {

br1=x/b%10;
br2=y/b%10;
brx--;
bry--;



      if(br1==br2)
      {
          if(nbr==0)
          {
              nbr+=br1*10+br1;
          }
          else
          {
            nbr=(nbr*10+br1)*10+br1;
          }
      }
      else if (br1>br2)
      {
          if(nbr==0)
          {
              nbr+=br1;
          }
          else
          {
            nbr=nbr*10+br1;
          }
      }
      else if (br2>br1)
      {
        if(nbr==0)
          {
              nbr+=br2;
          }
          else
          {
            nbr=nbr*10+br2;
          }
      }


      if(brx<=0 || bry<=0)
      {
          log:
          b*=10;
          br1=x/b%10;
          br2=y/b%10;
           nbr=nbr*10+br2;
           if(brx<=0 && bry<=0)
           {
               goto end;
           }
           brx--;
           bry--;



           goto log;
      }

b*=10;

  }
end:
 while(nbr!=0)
  {
     nbr2=nbr%10;
     obrnuto=obrnuto*10+nbr2;
     nbr/=10;
  }
printf("\n\n%d", obrnuto);
    return 0;
}