#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  string arr[n];
  for (int i = 0; i < n; i++) {
    cin >> arr[i];
  }
  int dist[n * m][n * m];
  for (int i = 0; i < n * m; i++) {
    for (int j = 0; j < n * m; j++) {
      dist[i][j] = INT_MAX / 3;
      if (i == j) {
        dist[i][j] = 0;
      }
    }
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (arr[i][j] == '#') {
        continue;
      }
      if (i > 0 and arr[i - 1][j] == '.') {
        dist[i * m + j][(i - 1) * m + j] = 1;
      }
      if (i < n - 1 and arr[i + 1][j] == '.') {
        dist[i * m + j][(i + 1) * m + j] = 1;
      }
      if (j > 0 and arr[i][j - 1] == '.') {
        dist[i * m + j][i * m + (j - 1)] = 1;
      }
      if (j < m - 1 and arr[i][j + 1] == '.') {
        dist[i * m + j][i * m + (j + 1)] = 1;
      }
    }
  }
  for (int k = 0; k < n * m; k++) {
    for (int j = 0; j < n * m; j++) {
      for (int i = 0; i < n * m; i++) {
        if (dist[i][k] + dist[k][j] < dist[i][j]) {
          dist[i][j] = dist[i][k] + dist[k][j];
        }
      }
    }
  }
  for (int i = 0; i < n * m; i++) {
    for (int j = 0; j < n * m; j++) {
      cout << setw(10) << dist[i][j] << " ";
    }
    cout << endl;
  }
  int sol = 0;
  cout << sol;
  return 0;
}
