#include <bits/stdc++.h>
#include <cstring>
#define endl '\n'
#define fi first
#define se second
#define eb emplace_back
#define pb push_back
#define ALL(A) A.begin(), A.end()
#define FOR(i, l, r) for (int i = l; i <= r; i++)
#define FOR2(i, l, r) for (int i = l; i >= r; i--)
#define ce cout<<endl;
using namespace std;
using ll = long long;
using pll = pair<ll, ll>;
using pii = pair<int, int>;
using str = string;
using T = pair<ll,int>;
const ll INF = 1e18;
const int N = 2e3 ;
const int MAXM = 4200005;
const int LOG2 = 18;
const int inv = 1112;
const int MOD = 998244353;
int dx[]= {0,0,-1,1};
int dy[] = {1 , - 1 , 0 , 0};
// Author : T_Danh - Tri An High School
ll mypow(ll a, ll b , ll mod ){
ll res = 1;
a %= mod;
while(b){
if(b & 1) res = res * a % mod;
a = a * a % mod;
b >>= 1;
}
return res;
}
int n , m;
int grid[N + 2][N + 2];
int dp[N + 1][N + 1];
int res= 0;
bool vis[N + 2][N + 2];
int V[N + 2][N + 2];
void cal(int ki, int L, int R, int optL, int optR) {
if (L > R) return;
int mid = (L + R) >> 1;
int best_i = -1;
int current_max = -1;
FOR(i, optL, min(mid - 1, optR)) {
int s = V[mid][i + 1] + dp[ki - 1][i];
// if(ki == 2 && mid == 4){
// cout << "FIX " << i << " " << dp[ki - 1][i] << " " << diff_prefix[mid][i + 1] <<endl;
// }
if (s > current_max) {
current_max = s;
best_i = i;
}
else if(s == current_max){
best_i = i;
}
}
dp[ki][mid] = current_max;
res = max(res , dp[ki][mid]);
cal(ki ,L, mid - 1, optL, best_i);
cal(ki ,mid + 1, R, best_i, optR);
}
bool inside(int i , int j){
return i > 0 && i <= n && j > 0 && j <= m && grid[i][j] != -1 && !vis[i][j];
}
void bfs(int si , int sj){
deque<pii> q;
q.eb(si , sj);
vis[si][sj] = true;
int l = sj , r = sj;
int W= 0 ;
while(!q.empty()){
int i = q.front().fi , j = q.front().se; q.pop_front();
W += grid[i][j];
for(int dir = 0 ; dir < 4 ; ++dir){
int ni = i + dx[dir];
int nj = j + dy[dir];
if(!inside(ni , nj)) continue;
vis[ni][nj] = true;
q.eb(ni , nj);
l = min(nj , l); r = max(nj , r);
}
}
FOR(i , l , r){
V[i][l] += W;
}
}
void solve() {
cin >> n >> m;
FOR(i,1,n){
FOR(j,1,m){
char c;
cin >> c;
if(c == '.'){
grid[i][j] = -1;
}
else{
grid[i][j] = c - '0';
}
}
}
FOR(i,1,n){
FOR(j,1,m){
if(inside(i , j)){
bfs(i , j);
}
}
}
FOR(j,1,m) FOR2(i, j - 1, 1){
V[j][i] += V[j][i + 1];
}
FOR(j,1,m){
dp[1][j] = V[j][1];
res = max(res , dp[1][j]);
}
cout << res <<endl;
FOR(i,2,m){
res = 0;
cal(i , i , m , i - 1 ,m);
cout << res <<endl;
}
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
int t = 1;
solve();
return 0;
}