#include <bits/stdc++.h>

using namespace std;

constexpr array<int, 4> DY = { -1, 1,  0, 0 };
constexpr array<int, 4> DX = {  0, 0, -1, 1 };

constexpr int M = 210;
constexpr int N = 210;
int m, n;
array<bitset<N>, N> mat, seen;
array<array<int, N>, M> neighborCnt;

bool isInBounds(int y, int x) {
    return 0 <= y && y < m && 0 <= x && x < n;
}

bool bfs(int srcY, int srcX) {
    queue<pair<int, int>> q;

    q.push(make_pair(srcY, srcX));
    seen[srcY][srcX] = true;

    bool hasEndpoint = false;
    bool canExtend = false;

    while (!q.empty()) {
        int y, x;
        tie(y, x) = q.front();
        q.pop();

        if (neighborCnt[y][x] <= 1) {
            hasEndpoint = true;
        }

        for (int i = 0; i < 4; ++i) {
            int yy = y + DY[i];
            int xx = x + DX[i];

            if (isInBounds(yy, xx)) {
                if (mat[yy][xx]) {
                    if (!seen[yy][xx]) {
                        seen[yy][xx] = true;
                        q.push(make_pair(yy, xx));
                    }
                } else if (neighborCnt[y][x] <= 1 && neighborCnt[yy][xx] == 1) {
                    canExtend = true;
                }
            }
        }
    }

    return hasEndpoint && !canExtend;
}

int main() {
    if (fopen("RAN.inp", "r")) {
        freopen("RAN.inp", "r", stdin);
        freopen("RAN.out", "w", stdout);
    }
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    cin >> m >> n;

    for (int y = 0; y < m; ++y) {
        for (int x = 0; x < n; ++x) {
            char tmp;
            cin >> tmp;
            mat[y][x] = (tmp == '1');
        }
    }

    for (int y = 0; y < m; ++y) {
        for (int x = 0; x < n; ++x) {
            for (int i = 0; i < 4; ++i) {
                int yy = y + DY[i];
                int xx = x + DX[i];

                if (isInBounds(yy, xx)) {
                    if (mat[yy][xx]) {
                        ++neighborCnt[y][x];
                    }
                }
            }
        }
    }

    int ans = 0;

    for (int y = 0; y < m; ++y) {
        for (int x = 0; x < n; ++x) {
            if (mat[y][x] && !seen[y][x]) {
                ans += bfs(y, x) ? 1 : 0;
            }
        }
    }

    cout << ans << '\n';

    return 0;
}
