#include <stdio.h>
#include <string.h>
#include <ctype.h>

#define MAX 1000

char stack[MAX][MAX];
int top = -1;

// Push string to stack
void push(const char *str)
{
    if (top < MAX - 1)
    {
        strncpy(stack[++top], str, MAX - 1);
        stack[top][MAX - 1] = '\0';
    }
}

// Pop string from stack
char *pop()
{
    return stack[top--];
}

// Check if character is an operator
int isOperator(char ch)
{
    return ch == '+' || ch == '-' || ch == '*' || ch == '/' || ch == '^';
}

// Check balanced parentheses
int isBalanced(const char *expr)
{
    int count = 0;
    for (int i = 0; expr[i]; i++)
    {
        if (expr[i] == '(')
            count++;
        else if (expr[i] == ')')
            count--;
        if (count < 0)
            return 0;
    }
    return count == 0;
}

int main()
{
    char prefix[MAX];
    scanf("%s", prefix);

    // Check parentheses
    if (!isBalanced(prefix))
    {
        printf("Invalid input");
        return 0;
    }

    int len = strlen(prefix);

    // Scan from right to left
    for (int i = len - 1; i >= 0; i--)
    {
        char ch = prefix[i];

        // Operand
        if (isalnum(ch))
        {
            char temp[2] = {ch, '\0'};
            push(temp);
        }
        // Operator
        else if (isOperator(ch))
        {
            if (top < 1)
            {
                printf("Invalid input");
                return 0;
            }

            char op1[MAX], op2[MAX], expr[MAX];
            strncpy(op1, pop(), MAX - 1);
            strncpy(op2, pop(), MAX - 1);

            snprintf(expr, MAX, "%s%s%c", op1, op2, ch);
            push(expr);
        }
        // Ignore parentheses
        else if (ch == '(' || ch == ')')
        {
            continue;
        }
        // Invalid character
        else
        {
            printf("Invalid input");
            return 0;
        }
    }

    // Final validation
    if (top != 0)
    {
        printf("Invalid input");
        return 0;
    }

    printf("%s", pop());
    return 0;
}