#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <cmath>
#include <algorithm>

using namespace std;
#define LL long long

int main()
{
	LL H;
	cin >> H;
	LL W;
	cin >> W;

	map<string, bool> S;
	for (long long i = 0; i < H; ++i)
	{
		for (long long j = 0; j < W; ++j)
		{
			char s;
			cin >> s;

			string label;
			label += to_string(j);
			label += ",";
			label += to_string(i);

			S[label] = (s == '#');
		}
	}

	LL result = 0;
	for (long long i = 1; i < H-1; ++i)
	{
		for (long long j = 1; j < W-1; ++j)
		{
			string label;
			label += to_string(j);
			label += ",";
			label += to_string(i);
			string above;
			above += to_string(j);
			above += ",";
			above += to_string(i - 1);
			string left;
			left += to_string(j - 1);
			left += ",";
			left += to_string(i);
			string right;
			right += to_string(j + 1);
			right += ",";
			right += to_string(i);
			string down;
			down += to_string(j);
			down += ",";
			down += to_string(i + 1);
			if (S[label])
			{
				if(!S[above] && !S[left])
				{
					result++;
				}
				if (!S[above] && !S[right])
				{
					result++;
				}
				if (!S[down] && !S[left])
				{
					result++;
				}
				if (!S[down] && !S[right])
				{
					result++;
				}
			}
			else
			{
				if (S[above] && S[left])
				{
					result++;
				}
				if (S[above] && S[right])
				{
					result++;
				}
				if (S[down] && S[left])
				{
					result++;
				}
				if (S[down] && S[right])
				{
					result++;
				}
			}
		}
	}

	cout << result << endl;
}

#include<bits/stdc++.h>
using namespace std;
int main() {
  int N, K;
  cin >> N >> K;
  vector<vector<int>> data(N, vector<int>(N));
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < N; j++) {
      cin >> data.at(i).at(j);
    }
  }
  
  int ans = 0;
  vector<int> cities(N);
  for (int i = 0; i < N; i++) {
    cities.at(i) = i;
  }
  do {
    if (cities.at(0) != 0) continue;
    int sum = 0;
    for (int i = 0; i < N; i++) {
      //cout << cities.at(i);
      // 往路
      if (i == N - 1) {
        sum += data.at(cities.at(i)).at(0);
      } else {
        sum += data.at(cities.at(i)).at(cities.at(i + 1));
      }
    }
    //cout << endl;
    if (sum == K) ans++;
  } while (next_permutation(cities.begin(), cities.end()));
  
  cout << ans << endl;
}