#include <bits/stdc++.h>
using namespace std;
string change(string x, int w);
string bsuma(string A, string B, int w);
string asumb(string A, string B, int w);
int main() {
  int h, w;
  string a, b, c;
  cin >> h >> w;
  if (h == 0 || w == 0) {
    return 0;
  }
  cin >> a;
  a = change(a, w);
  for (int i = 0; i < (h - 1) / 2; i++) {
    cin >> b;
    b = change(b, w);
    a = bsuma(a, b, w);
    b = asumb(a, b, w);
    cout << a << endl;
    cin >> a;
    a = change(a, w);
    a = bsuma(a, b, w);
    b = asumb(a, b, w);
    cout << b << endl;
  }
  if (h % 2 == 1) {
    cout << a << endl;
  } else {
    cin >> b;
    b = change(b, w);
    a = bsuma(a, b, w);
    b = asumb(a, b, w);
    cout << a << endl;
    cout << b << endl;
  }
}
string change(string x, int w) {
  for (int i = 0; i < w; i++) {
    if (x.at(i) == '.') {
      x.at(i) = '0';
    }
  }
  if (x.at(0) == '#' && x.at(1) != '#') {
    x.at(1)++;
  }
  if (x.at(w - 1) == '#' && x.at(w - 2) != '#') {
    x.at(w - 2)++;
  }
  for (int i = 1; i < w - 1; i++) {
    if (x.at(i) == '#' && x.at(i - 1) == '#' && x.at(i + 1) != '#') {
      x.at(i + 1)++;
    } else if (x.at(i) == '#' && x.at(i - 1) != '#' && x.at(i + 1) == '#') {
      x.at(i - 1)++;
    } else if (x.at(i) == '#' && x.at(i - 1) != '#' && x.at(i + 1) != '#') {
      x.at(i + 1)++;
      x.at(i - 1)++;
    }
  }
  return x;
}
string bsuma(string A, string B, int w) {
  if (B.at(0) == '#') {
    if (A.at(0) != '#') {
      A.at(0)++;
    }
    if (A.at(1) != '#') {
      A.at(1)++;
    }
  }
  if (B.at(w - 1) == '#') {
    if (A.at(w - 1) != '#') {
      A.at(w - 1)++;
    }
    if (A.at(w - 2) != '#') {
      A.at(w - 2)++;
    }
  }
  for (int i = 1; i < w - 1; i++) {
    if (B.at(i) == '#') {
      if (A.at(i - 1) != '#') {
        A.at(i - 1)++;
      }
      if (A.at(i) != '#') {
        A.at(i)++;
      }
      if (A.at(i + 1) != '#') {
        A.at(i + 1)++;
      }
    }
  }
  return A;
}
string asumb(string A, string B, int w) {
  if (A.at(0) == '#') {
    if (B.at(0) != '#') {
      B.at(0)++;
    }
    if (B.at(1) != '#') {
      B.at(1)++;
    }
  }
  if (A.at(w - 1) == '#') {
    if (B.at(w - 1) != '#') {
      B.at(w - 1)++;
    }
    if (B.at(w - 2) != '#') {
      B.at(w - 2)++;
    }
  }
  for (int i = 1; i < w - 1; i++) {
    if (A.at(i) == '#') {
      if (B.at(i - 1) != '#') {
        B.at(i - 1)++;
      }
      if (B.at(i) != '#') {
        B.at(i)++;
      }
      if (B.at(i + 1) != '#') {
        B.at(i + 1)++;
      }
    }
  }
  return B;
}
