#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007
//#define MOD 998244353
#define INF 1000000010
#define EPS 1e-9
#define F first
#define S second

#define debug(x) cout<<x<<endl;
#define repi(i,x,n) for(int i=x;i<n;i++)
#define rep(i,n) repi(i,0,n)
#define lp(i,n) repi(i,0,n)
#define repn(i,n) for(int i=n;i>=0;i--)
#define int long long
#define endl "\n"

typedef pair<int,int> PII;
typedef pair<int,string> PIS;
typedef pair<string,int> PSI;


signed main(){
  cin.tie(0);	
  ios::sync_with_stdio(false);
  int h,w;
  cin>>h>>w;
  char mp[h][w];
  rep(i,h){
    rep(j,w){
      cin>>mp[i][j];
    }
  }
  int ans=0;
  rep(i,h){
    rep(j,w){
      if(mp[i][j]=='.'){
	if(i!= h-1 && mp[i+1][j]=='.') ans++;
	if(j!= w-1 && mp[i][j+1]=='.') ans++;
      }
    }
  }
  cout<<ans<<endl;
	
      


  return 0;
}

//author: hitch_hiker42;
#include<bits/stdc++.h>
using namespace std;

//solution:
#define int int64_t
#define span(a) begin(a), end(a)

void hike() {
  int n, k; cin >> n >> k;
  int cost[n + 1][n + 1];
  for(int i = 1; i <= n; ++i) {
    for(int j = 1; j <= n; ++j) cin >> cost[i][j];
  }
  vector<int> path(n - 1);
  iota(span(path), 2);
  int count = 0;
  do {
    int i = 1, sum = 0;
    for(int& j: path) {
      sum += cost[i][j], i = j;
    }
    sum += cost[i][1];
    count += (sum == k);
  } while(next_permutation(span(path)));
  cout << count << "\n";
}

signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr); cout.tie(nullptr);
  int t = 1; //cin >> t;
  while(t--) hike();
  return 0;
} //farewell, until we meet again..