#include<stdio.h>

int main()
{
 
  int x, c1, c2, c3, c4, c5;
  int zbir, proizvod;
  
  scanf("%d", &x);
  
  if(x<10000 || x>99999)
  {
    printf("-1\n");
    return -1;
  }
  
  c1 = x%10;       //cifra jedinica
  c2 = (x/10)%10;  //cifra destica
  c3 = (x/100)%10; //cifra stotina
  c4 = (x/1000)%10;//cifra hiljada
  c5 = x/10000;    //cifra desetina hiljada
  
  if((c1 < c2 < c3 < c4 < c5) || (c5 < c4 < c3 < c2 < c1))
  {
    zbir = c1+c2+c3+c4+c5;
    printf("%d\n", zbir);
  }
  
  else if((c1 > c2 < c3 > c4 < c5) || (c5 < c4 > c3 < c2 > c1))
  { 
    proizvod = c1*c2*c3*c4*c5;
    printf("%d\n", proizvod);
  }
  
  else 
  {
    printf("%d\n", x);
  }
  
  return 0;
}