#include <stdio.h>
#include <limits.h>


int main ()
{
	int br, j, d, s, min=INT_MAX;

	scanf ("%d", &br);

	if (br<100 || br>999){
		printf ("-1\n");
		return 1;
	}

	j=br%10;
	d=(br/10)%10;
	s=br/100;

	br=s*100+d*10+j;

	if (br<min)
		min=br;

	br=s*100+j*10+d;
	
	if (br<min)
		min=br;

	br=d*100+s*10+j;

	if (br<min)
		min=br;

	br=d*100+j*10+s;
	
	if (br<min)
		min=br;

	br=j*100+s*10+d;

	if (br<min)
		min=br;

	br=j*100+d*10+s;

	if (br<min)
		min=br;

	printf ("%d\n", min);



	return 0;
}
