#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<ctype.h>

#define MAX_SIZE 1000

char stack[MAX_SIZE][MAX_SIZE];
int top =-1;

void push(char* str)
{
    if(top>= MAX_SIZE -1)
    {
        printf("Stack overflow\n");
    }
    top++;
    strcpy(stack[top],str);
}

char* pop()
{
    if(top==-1)
    {
        return NULL;
    }
    return stack[top--];
}

int is_operator(char ch)
{
    return(ch == '+'|| ch == '-' || ch == '*' || ch == '/' || ch == '^');
}

int main()
{
    char prefix[MAX_SIZE];
    scanf("%s",prefix);
    
    int len = strlen(prefix);
    char result[MAX_SIZE];
    
    for(int i= len-1;i>=0;i--)
    {
        if(isalnum(prefix[i]))
        {
            char operand[2];
            operand[0] = prefix[i];
            operand[1] = '\0';
            push(operand);
        }
        else if(isoperator(prefix[i]))
        {
            char* op1 = pop();
            char* op2 = pop();
            
            if(op1 == NULL || op2 == NULL)
            {
                printf("Invalid input\n");
                return 1;
            }
            strcpy(result,op1);
            strcpy(result,op2);
            char operator_str[2];
            operator_str[0] = prefix[i];
            operator_str[1] = '\0';
            strcat(result,operator_str);
            push(result);
        }
        else
        {
            printf("Invalid input\n");
            return 1;
        }
    }
    if(top ==0)
    {
        printf("%s\n",pop());
    }
    else
    {
        printf("Invalid input\n");
    }
    return 0;
}