#include <bits/stdc++.h>
using namespace std;
int main() {
  int H, W;
  cin >> H >> W;
  string A, B, C;
  cin >> A >> B >> C;
  if (A.at(0) == '#') {
    cout << '#';
  } else {
    int a = 0;
    if (A.at(1) == '#') {
      a++;
    }
    if (B.at(0) == '#') {
      a++;
    }
    if (B.at(1) == '#') {
      a++;
    }
    cout << a;
  }
  for (int i = 1; i < W - 1; i++) {
    if (A.at(i) == '#') {
      cout << '#';
    } else {
      int a = 0;
      if (A.at(i - 1) == '#') {
        a++;
      }
      if (A.at(i + 1) == '#') {
        a++;
      }
      if (B.at(i - 1) == '#') {
        a++;
      }
      if (B.at(i) == '#') {
        a++;
      }
      if (B.at(i + 1) == '#') {
        a++;
      }
      cout << a;
    }
  }
  if (A.at(W - 1) == '#') {
    cout << '#' << endl;
  } else {
    int a = 0;
    if (A.at(W - 2) == '#') {
      a++;
    }
    if (B.at(W - 2) == '#') {
      a++;
    }
    if (B.at(W - 1) == '#') {
      a++;
    }
    cout << a << endl;
  }
  for (int j = 1; j < W - 1; j++) {
    if (B.at(0) == '#') {
      cout << '#';
    } else {
      int a = 0;
      if (A.at(0) == '#') {
        a++;
      }
      if (A.at(1) == '#') {
        a++;
      }
      if (B.at(1) == '#') {
        a++;
      }
      if (C.at(0) == '#') {
        a++;
      }
      if (C.at(1) == '#') {
        a++;
      }
      cout << a;
    }
    for (int i = 1; i < W - 1; i++) {
      if (A.at(i) == '#') {
        cout << '#';
      } else {
        int a = 0;
        if (A.at(i - 1) == '#') {
          a++;
        }
        if (A.at(i) == '#') {
          a++;
        }
        if (A.at(i + 1) == '#') {
          a++;
        }
        if (B.at(i - 1) == '#') {
          a++;
        }
        if (B.at(i + 1) == '#') {
          a++;
        }
        if (C.at(i - 1) == '#') {
          a++;
        }
        if (C.at(i) == '#') {
          a++;
        }
        if (C.at(i + 1) == '#') {
          a++;
        }
        cout << a;
      }
    }
    if (B.at(W - 1) == '#') {
      cout << '#' << endl;
    } else {
      int a = 0;
      if (A.at(W - 2) == '#') {
        a++;
      }
      if (A.at(W - 1) == '#') {
        a++;
      }
      if (B.at(W - 2) == '#') {
        a++;
      }
      if (C.at(W - 2) == '#') {
        a++;
      }
      if (C.at(W - 1) == '#') {
        a++;
      }
      cout << a << endl;
    }
    A = B;
    B = C;
    string S;
    cin >> S;
    C = S;
  }
  if (C.at(0) == '#') {
    cout << '#';
  } else {
    int a = 0;
    if (B.at(0) == '#') {
      a++;
    }
    if (B.at(1) == '#') {
      a++;
    }
    if (C.at(1) == '#') {
      a++;
    }
    cout << a;
  }
  for (int i = 1; i < W - 1; i++) {
    if (C.at(i) == '#') {
      cout << '#';
    } else {
      int a = 0;
      if (C.at(i - 1) == '#') {
        a++;
      }
      if (C.at(i + 1) == '#') {
        a++;
      }
      if (B.at(i - 1) == '#') {
        a++;
      }
      if (B.at(i) == '#') {
        a++;
      }
      if (B.at(i + 1) == '#') {
        a++;
      }
      cout << a;
    }
  }
  if (C.at(W - 1) == '#') {
    cout << '#' << endl;
  } else {
    int a = 0;
    if (B.at(W - 2) == '#') {
      a++;
    }
    if (C.at(W - 2) == '#') {
      a++;
    }
    if (B.at(W - 1) == '#') {
      a++;
    }
    cout << a << endl;
  }
}
