#include <bits/stdc++.h>
using namespace std;
int dx[4] = {0, 1, 0, 1}, dy[4] = {0, 0, 1, 1};
int main(){
    int H, W;
    cin >> H >> W;
    vector<string> S(H);
    for(int i = 0; i < H; i++) cin >> S[i];
    int ans = 0;
    for(int i = 0; i < H - 1; i++){
        for(int j = 0; j < W - 1; j++){
            int cnt = 0;
            for(int k = 0; k < 4; k++){
                int nx = i + dx[k], ny = j + dy[k];
                if(S[nx][ny] == '#') cnt++;
            }
            if(cnt % 2 == 1) ans++;
        }
    }
    cout << ans << endl;
}
#include <bits/stdc++.h>
using namespace std;
//#include <atcoder/all>
//using namespace atcoder;
//using mint = modint1000000007;
//using mint = modint998244353;
template <typename T> bool chmax(T &u, const T z) { if (u < z) {u = z; return true;} else return false; }
template <typename T> bool chmin(T &u, const T z) { if (u > z) {u = z; return true;} else return false; }
#define ll long long
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
typedef pair<ll, int> P;
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }
ll lcm(ll a, ll b){return a * b / gcd(a, b);}

long long Seigenjikan=50000;//1800000;//実行時間1000000で1秒
long long Seigenjikan2=1900000;//1800000;//実行時間1000000で1秒
long long time_s;
clock_t endt,start;
int t[100][100];//入力受け取りタイルセット
int p[100][100];//タイルの得点
vector<int>used(2525,0);//タイルセットの使用を確認
int vx[4]={-1,1,0,0};
int vy[4]={0,0,-1,1};
char moji[4]={'U','D','L','R'};
int tmp_score,best_score;
string tmp_ans,best_ans;

void dfs(int x,int y){
  //時間を計測
  endt = clock();
  time_s = endt - start; 
  if(time_s>Seigenjikan)return;
  used[t[x][y]]=1;
  tmp_score+=p[x][y];
  if(tmp_score>best_score){
    best_ans=tmp_ans;
    best_score=tmp_score;
  }
  rep(i,4){
    if(x+vx[i]<0||x+vx[i]>49||y+vy[i]<0||y+vy[i]>49)continue;
    if(used[t[x+vx[i]][y+vy[i]]]==1)continue;
    tmp_ans.push_back(moji[i]);
    dfs(x+vx[i],y+vy[i]);
  }
  used[t[x][y]]=0;
  tmp_ans.pop_back();
  return;
}
int main(){
  start = clock();
  int si,sj,tmp_score,best_score=0;
  string ans="",A="";
  cin>>si>>sj;
  int x=si;
  int y=sj;
  rep(i,50)rep(j,50)cin>>t[i][j];
  rep(i,50)rep(j,50)cin>>p[i][j];

  dfs(x,y);
  cout<<best_ans<<endl;
  return 0;
}