#include "testlib.h"
#include <bits/stdc++.h>
using namespace std;
int n,m;
char a[5005][5005];
int calc(){
	int ans=0;
	for(int i=1;i<=n;i++){
		int cnt=0;
		for(int j=1;j<=m;j++){
			if(a[i][j]=='(') ++cnt;
			else --cnt;
			if(cnt<0) {
				cnt=-1; break;
			}
		}
		if(cnt==0) ans++;
	}
	for(int j=1;j<=m;j++){
		int cnt=0;
		for(int i=1;i<=n;i++){
			if(a[i][j]=='(') ++cnt;
			else --cnt;
			if(cnt<0) {
				cnt=-1; break;
			}
		}
		if(cnt==0) ans++;
	}
	return ans;
}
int main(int argc, char* argv[]) {
	registerTestlibCmd(argc, argv);
	n=inf.readInt();
	m=inf.readInt();
	for(int i=1;i<=n;i++){
		string s=ouf.readLine();
		if((int)s.length()!=m) quitf(_wa,"wrong format: readed %d chars from line %d.\n",(int)s.length(),i);
		for(char c:s) if(c!='('&&c!=')') quitf(_wa,"wrong format: read neither '(' nor ')'.");
		for(int j=1;j<=m;j++){
			a[i][j]=s[j-1];
		}
	}
	int part_ans=calc();
	for(int i=1;i<=n;i++){
		string s=ans.readLine();
		if((int)s.length()!=m) quitf(_fail,"answer file wrong format: readed %d chars from line %d.\n",(int)s.length(),i);
		for(char c:s) if(c!='('&&c!=')') quitf(_wa,"answer file wrong format: read neither '(' nor ')'.");
		for(int j=1;j<=m;j++){
			a[i][j]=s[j-1];
		}
	}
	int correct_ans=calc();
	if(part_ans==correct_ans){
		quitf(_ok,"accepted, n=%d, m=%d, found ans = %d.\n",n,m,correct_ans);
	}else{
		quitf(_wa,"wrong answer, n=%d, m=%d, found ans = %d, correct = %d.\n",n,m,part_ans,correct_ans);
	}
}
