#include using namespace std; using ll = long long; templatebool chmax(T &a, const T &b) { if (abool chmin(T &a, const T &b) { if (b A){ ll L = A.size(); FOR(i, 0, L){ if(i) cout << ' '; cout << A[i]; } cout << endl; } struct Point{ ll x; ll y; Point(ll x, ll y): x(x), y(y) {} Point(){} }; int dx[4] = {-1, 0, 1, 0}; int dy[4] = {0, 1, 0, -1}; ll A[3010][3010]; int main(){ cin.tie(0); ios::sync_with_stdio(false); // input ll H, W; cin >> H >> W; FOR(i, 0, H){ FOR(j, 0, W){ cin >> A[i][j]; } } queue que; ll count = 0; FOR(y, 0, H){ FOR(x, 0, W){ if(A[y][x]==1){ count++; que.push(Point(x, y)); A[y][x] = 0; while(!que.empty()){ auto po = que.front(); que.pop(); FOR(i, 0, 4){ ll tx = po.x + dx[i]; ll ty = po.y + dy[i]; if(0<=tx && tx