#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i, s, n) for (int i = (s); i < (n); ++i)
#define rrep(i, n) for (int i = n - 1; i >= 0; --i)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define len(x) (int)(x).size()
#define pb push_back
#define em emplace_back
#define vi vector<int>
#define vl vector<long long>
#define vs vector<string>
#define vc vector<char>
#define vd vector<double>
#define vb vector<bool>
#define vvi vector<vector<int>>
#define vvl vector<vector<long long>>
#define fast  \
  cin.tie(0); \
  ios::sync_with_stdio(false);
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;

int main() {
  fast;
  int h, w;
  cin >> h >> w;
  vs s(h + 2, "");
  rep(i, 0, w + 2) {
    s[0] += '.';
    s[h + 1] += '.';
  }
  rep(i, 1, h + 1) cin >> s[i];
  int a = h + 1, b = w + 1;
  rep(i, 1, h + 1) {
    s[i] = "." + s[i];
    s[i] += ".";
  }
  int ans = 0;
  rep(i, 0, a) rep(j, 0, b) {
    int cnt = 0;
    if (s[i][j] == '.') ++cnt;
    if (s[i][j + 1] == '.') ++cnt;
    if (s[i + 1][j] == '.') ++cnt;
    if (s[i + 1][j + 1] == '.') ++cnt;
    if (cnt == 3 || cnt == 1) ++ans;
  }
  cout << ans << endl;
  return 0;
}
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC loop-opt(on)

#define rep(i, a, b) for(int i = a; i <= b; i++)
#define rrep(i, a, b) for(int i = b; i >= a; i--)
#define print(x) cout << #x <<" = " << x <<"\n"
#define pprint(x) cout << #x <<" = (" << x.first <<", " << x.second <<")\n"
#define all(x) x.begin(), x.end()
#define ceil(a, b) ((a + b - 1) / (b))

#define INF 1000000000000000000
#define MAXN 200 
#define MOD 1000000007
#define eps (1e-9)

#define int long long int
#define lld long double
#define pii pair<int, int>
#define random mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count())

using namespace std;
int n, m, c[MAXN * MAXN], d[MAXN * MAXN];
int ans[MAXN*MAXN], v[MAXN*MAXN];
pii p[MAXN*MAXN];
int mp[MAXN][MAXN], timestamp, a, b;
void dfs(int x) {
	d[x] = ++timestamp;
	rep(i, 1, n) {
		if(c[i] == c[x] && !d[i] && mp[i][x]) {
			mp[x][i] = -1, mp[i][x] = -2;
			dfs(i);
		}
	}
	return;
}
void solve() {
	timestamp = 0;
	rep(i, 1, n) {
		if(!d[i]) d[i] = 1, dfs(i);
	}
	rep(i, 1, m) {
		tie(a, b) = p[i];
		if(c[a] > c[b]) ans[i] = -1;
		else if(c[b] > c[a]) ans[i] = -2;
		else if(mp[a][b] < 0) ans[i] = mp[a][b];
		else ans[i] = (d[a] > d[b] ? -1 : -2); 
		mp[a][b] = ans[i];
		mp[b][a] = -3 - ans[i];
	} 
	return ;
}
int dfs1(int x) {
	int cnt = 1; v[x] = 1;
	rep(i, 1, n) {
		if(!v[i] && mp[x][i] == -1) cnt += dfs1(i);
	}
	return cnt;
}
bool check() {
	rep(i, 1, n) {
		memset(v, 0, sizeof(v));
		if(dfs1(i) != c[i]) return false;
	}
	return true;
}
signed main() {
	ios::sync_with_stdio(false), cin.tie(0);
	cin >> n >> m;
	rep(i, 1, m) {
		cin >> a >> b;
		p[i] = {a, b};
		mp[a][b] = mp[b][a] = 1;
	}
	rep(i, 1, n) cin >> c[i];
	solve();
	assert(check());
	rep(i, 1, m) {
		if(ans[i] == -1) cout <<"->\n";
		else cout <<"<-\n"; 
	}
	return 0;
}