#include <bits/stdc++.h>
const int INF = 1 << 29;
int main() {
  std::ios_base::sync_with_stdio(false);
  std::cin.tie(NULL);
  ;
  int n, m;
  std::cin >> n >> m;
  std::vector<std::vector<int>> v;
  for (int i = 0; i < n; i++) {
    std::vector<int> tmp;
    std::string in;
    std::cin >> in;
    for (int j = 0; j < m; j++) {
      char c = in[j];
      int put = -2;
      if (c == '*') {
        put = -1;
      } else if (c == '.') {
        put = 0;
      } else
        put = (int)c - '0';
      tmp.push_back(put);
    }
    v.push_back(tmp);
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (v[i][j] == -1) continue;
      int cnt = 0;
      if (i > 0) {
        if (j > 0)
          if (v[i - 1][j - 1] == -1) cnt++;
        if (v[i - 1][j] == -1) cnt++;
        if (j < m - 1)
          if (v[i - 1][j + 1] == -1) cnt++;
      }
      if (i < n - 1) {
        if (j > 0)
          if (v[i + 1][j - 1] == -1) cnt++;
        if (v[i + 1][j] == -1) cnt++;
        if (j < m - 1)
          if (v[i + 1][j + 1] == -1) cnt++;
      }
      if (j > 0) {
        if (v[i][j - 1] == -1) cnt++;
      }
      if (j < m - 1) {
        if (v[i][j + 1] == -1) cnt++;
      }
      if (cnt != v[i][j]) {
        std::cout << "NO";
        return 0;
      }
    }
  }
  std::cout << "YES";
  return 0;
}
