#include<stdio.h>
#include<ctype.h>
int main(){
    int n;
    char exp[50];
    int num[50], ntop=-1;
    char op[50];
    int otop=-1;
    scanf("%d", &n);
    if(n<0){
        printf("Invalid input");
        return 0;
    }
    getchar();
    scanf("%[^\n]", exp);
    for(int i=0;exp[i];i++){
        if(exp[i]==' ') continue;
        if(isdigit(exp[i])){
            int val=0;
            while(isdigit(exp[i])){
                val=val*10+(exp[i]- '0');
                i++;
            }
            num[++ntop]=val;
            i--;
        }
        else if(exp[i]=='('){
            op[++otop]='(';
        }
        else if(exp[i]==')'){
            while(op[otop] != '('){
                int b=num[ntop--];
                int a=num[ntop--];
                char c=op[otop--];
                num[++ntop]=(c=='+')? a+b:
                (c=='-')? a-b:
                (c=='*')? a*b: a/b;
            }
            otop--;
        }
        else{
            while(otop>= && 
            (op[otop]=='*' || op[otop]=='/') ||
            ((op[otop]=='+' || op[otop]=='-') &&
            (exp[i]=='+' || exp[i]=='-')))){
                int b=num[ntop--];
                int a=num[ntop--];
                char c=op[ntop--];
           num[++ntop]=(c=='+')? a+b:
                (c=='-')? a-b:
                (c=='*')? a*b: a/b;
            }
            op[++otop]=exp[i]; 
            }
    }
    while (otop>=0){
        int b=num[ntop--];
                int a=num[ntop--];
                char c=op[ntop--];
           num[++ntop]=(c=='+')? a+b:
                (c=='-')? a-b:
                (c=='*')? a*b: a/b;
    }
    printf("%d", num[ntop]);
    return 0;
}