//zelovoc
#include<cstdio>
#include<vector>
#include<iostream>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<cstring>
#include<cmath>

using namespace std;
#define For(i,n) for(int i = 0; i<int(n); ++i)
#define INF 1023456789
#define LINF 1023456789123456789LL

typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<int> vint;

#define db(x) //cerr << #x << " = " << x << endl

char G[4][1047];
string S;

int cislo(int y, int x, int s) {
	int res = 0;
	For(i, s) {
		if (G[y][x+i] == ' ') continue;
		res = res*10 + (G[y][x+i] - '0');
	}
	return res;
}

int simple(int y, int x, int r, int s) {
	//string coho = "'";
	//For(i, s) coho += G[y][x+i];
	//coho+="'";	
	//db(coho);
	int lastpos = 0;
	vector<int> cisla;
	vector<int> znamienka;
	For(i, s) {
		if (G[y][x+i] == '+' || G[y][x+i] == '-' || G[y][x+i] == '*') {
			znamienka.push_back(G[y][x+i]);
			cisla.push_back(cislo(y,x+lastpos,i-lastpos));
			lastpos = i+1;
		}
	}
	cisla.push_back(cislo(y,x+lastpos, s-lastpos));
	//db(cisla[0]);
//	db(cisla.size());
//	db(znamienka.size());

	vector<int> termy;
	vector<int> znaky;
	For(i, cisla.size()) {
		if (i>0 && znamienka[i-1]=='*') {
			termy.back()*=cisla[i];
		} else {
			termy.push_back(cisla[i]);
			if (i>0) znaky.push_back(znamienka[i-1]);
		}
	}
//	db(termy.size());
//	db(znaky.size());
	
	int result = 0;
	For(i, termy.size()) {
		if (i>0 && znaky[i-1] == '-')
			result -= termy[i];
		else 
			result += termy[i];
		//db(termy[i]);
		//db(result);
	}
	db(result);
	return result;
}

int almostsimple(int y, int x, int r, int s) {
	if (G[y+1][x] == ' ') return almostsimple(y,x+1,r,s);
	if (G[y+1][x] == '=') 
		return simple(y,x,1,s)/simple(y+2,x,1,s);
	if (G[y+1][x] == '\\')
		return int(0.01+sqrt(double(simple(y+1,x+2,1,s-2))));
	return simple(y+1,x,1,s);
}

int formula(int y, int x, int r, int s) {
	if (r==1) {
		return simple(y,x,r,s);
	} else {
		int result = 0;
		int lasts = 0;
		int lastz = 1;
		For(i, s) {
			if ((G[y+1][x+i] == '+' || 
			     G[y+1][x+i] == '-') && G[y][x+i] == ' ') {
				result += lastz * almostsimple(y, lasts, r, i-lasts);
				lastz = (G[y+1][x+i] == '+')?1:-1;
				lasts = i+1;
			}
		}
		result += lastz * almostsimple(y, lasts, r, s-lasts);
		return result;
	}

}

int main() {
	int r,s;
	while((cin >> r >> s) && r + s > 0) {
		getline(cin, S);
		For(i, 4) For(j, s+4) G[i][j] = ' ';
		For(i, r) {
			getline(cin, S);
			For(j, S.size()) G[i][j] = S[j];
			G[i][s] = ' ';
			G[i][s+1] = 0;
		}
		cout << formula(0,0,r,s) << endl;
		getline(cin, S);
	}
}