#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<math.h>
#include<cstring>
#include<map>
using namespace std;
typedef pair<int, int> PII;
const int N = 1010;
int m, n;
string mt[N][N];
bool st[N][N];
int ori[4][2] = { {1,0},{-1,0},{0,1},{0,-1} };
bool flag;
int cnt = 0;
int bfs(int x, int y)
{
flag = 0;
cnt = 0;
queue<PII>q;
q.push({ x, y });
while (q.size())
{
auto t = q.front();
q.pop();
int fi = t.first;
int se = t.second;
cnt++;
for (int i = 0; i < 4; i++)
{
int a = fi + ori[i][0];
int b = se + ori[i][1];
if (a <= n && a > 0 && b <= m && b > 0)
{
if (!st[a][b] && mt[a][b] != "*")
{
q.push({ a,b });
st[a][b] = 1;
}
}
else flag = 1;
}
}
if (flag)return 0;
else return cnt;
}
int main()
{
cin >> n >> m;
string str;
for (int i = 1; i <= n; i++)
{
cin >> str;
for (int j = 1; j <= m; j++)mt[i][j] = str[j - 1];
}
int ans = 0;
for (int i = 1; i <= n; i++)
for (int j = 1; j <= m; j++)
if (!st[i][j] && mt[i][j] =="0")ans += bfs(i, j);
cout << ans;
return 0;
}