#include <stdio.h>
int main() {
	int x, sredina = 0, jedinice, desetice, stotine, max, min;
	
	scanf("%d", &x);
	 
	if(x < 100 || x > 999)
	{
	  printf("-1");
	  return -1;
	}
	
	jedinice = x%10;
	stotine = x/100;
	desetice = x/10 - stotine*10;
	min = jedinice;
	
	if(desetice < min)
	  min = desetice;
	
	if(stotine < min)
	  min = stotine;
	
	max = jedinice;
	
	if(desetice > max)
	  max = desetice;
	
	if(stotine > max)
	  max = stotine;
	
	if(stotine != max && stotine != min)
	  sredina = stotine;
	
	if(desetice != max && desetice != min)
	  sredina = desetice;
	
	if(jedinice != max && jedinice != min)
	  sredina = jedinice;
	
	if ((jedinice == max && desetice == max) || (stotine == max && desetice == max) || (jedinice == max && stotine == max))
	  sredina = max;
	if ((jedinice == min && desetice == min) || (stotine == min && desetice == min) || (jedinice == min && stotine == min))
	  sredina = min;
	
	
	if(jedinice == desetice && desetice == stotine)
	{ 
	  printf("%d", x);
	  return -1;
	}
	printf("%d", max+sredina*10+min*100);
	
	return 0;
	
}