#include <stdio.h>

int main()
{
  int n, min=9, max=0, c, s=0;
  
  scanf("%d", &n);
  
  if(n<=99 || n>=1000)
  {
    printf("-1");
    return -1;
  }
  
  while(n)
  {
    c=n%10;
    if(c>max)
      max=c;
    if(c<min)
      min=c;
    s+=c;
    n/=10;
  }
  s=s-min-max;
  n=min*100 + s*10 + max;
  
  printf("%d", n);
  
  
  return 0;
}