#include<stdio.h>

int main()
{
  int n, m, c1, c2, c3, max, min;
  scanf("%d", &n);
  if(n<100 || n>999)
  {
    printf("-1");
    return -1;
  }
  c1=n%10;
  n/=10;
  c2=n%10;
  n/=10;
  c3=n%10;
  min=c1;
  if(c2<min)
    min=c2;
  if(c3<min)
    min=c3;
  max=c1;
  if(c2>max)
    max=c2;
  if(c3>max)
    max=c3;
  m=min*100+(c1+c2+c3-min-max)*10+max;
  printf("%d", m);
  return 0;
}
