#include <iostream>
#include <string>
#include <cmath>

using namespace std;

int R, C;
string M[3];

struct Rec{
    int x, y;
    long long n;
};

Rec number(int x, int y){
    int I = 0;
    for(; M[y][x] >= '0' && M[y][x] <= '9'; x++)
        I = I * 10 + M[y][x] - '0';
    Rec r;
    r.x=x;
    r.y=y;
    r.n=I;
    return r;
}


long long term(int y, int x1, int x2){
    long long N=1;
    Rec r = number(x1,y);
    N = r.n;
    x1 = r.x;
    if(x1>x2) return N;
    while(true){
        x1++;
        char op = M[y][x1];
        x1+=2;
        Rec r = number(x1,y);
        x1 = r.x;
        switch(op){
            case '*': N *= r.n; break;
        }

        if(x1>x2)break;
    }
    //cout << "term=" << N << endl;
    return N;
}

long long simple(int y, int x1, int x2){
    //cout << "simple: " << y << ' ' << x1 << ' ' << x2 <<endl;
    long long N=0,x;
    int op = 1;
    while(M[y][x1] == ' ') x1++;
    for(x = x1;x<x2; x++){
        if(M[y][x] == '+'){
            N += op * term(y,x1,x-1);
            x1 = x+2;
            op = 1;
        }else if(M[y][x] == '-'){
            N += op * term(y,x1,x-1);
            x1 = x+2;
            op = -1;
        }
    }
    N += op * term(y,x1,x2);
    //cout << "simple=" << N << endl;
    return N;
}

long long mix(int y, int x1, int x2){
    //cout << "mix: " << y << ' ' << x1 << ' ' << x2 <<endl;
    char c = M[y][x1];
    if(c == '='){
        return simple(y-1,x1,x2) / simple(y+1,x1,x2);
    }else if(c == '\\'){
        return sqrt(simple(y,x1+2,x2));
    }else return simple(y,x1,x2);
    return 0;
}

long long all(int y, int x1, int x2){
    long long N=0,x;
    int op = 1;
    for(x = x1;x<x2; x++){
        if(R>1 && M[y-1][x]=='_')continue;
   
        if(M[y][x] == '+'){
            //cout << "all+:"<<endl;
            N += op * mix(y,x1,x-1);
            x1 = x+2;
            op = 1;
        }else if(M[y][x] == '-'){
            //cout << "all-:"<<endl;
            N += op * mix(y,x1,x-1);
            x1 = x+2;
            op = -1;
        }
    }
    N += op * mix(y,x1,x2);
    return N;
}


int main(){
    
    while(true){
        cin>>R>>C;
        if(R==0) return 0;
        getline(cin,M[0]);
        for(int i=0; i<R; i++)
            getline(cin,M[i]);
        /*for(int i=0; i<R; i++)
            cout<<'['<<M[i]<<']'<<endl;*/
            
        int y = 0;
        if(R!=1) y = 1;
            
                 
        cout << all(y,0,C-1) << endl;
    }
}