#include <bits/stdc++.h>
using namespace std;
int main() {
  int H, W;
  cin >> H >> W;
  char S[25][25];
  for (int i = 1; i <= H; i++) {
    for (int j = 1; j <= W; j++) {
      cin >> S[i][j];
    }
  }
  if (H == W)
    cout << (H - 1) * (H - 1) << endl;
  else
    cout << (H - 1) * (W - 1) + 2 << endl;
  return 0;
}
