#include <bits/stdc++.h>
using namespace std;
int checkEmpty(char A[101][101], int x, int y, int n, int m) {
  for (int i = max(x - 1, 0); i <= min(x + 1, n - 1); ++i) {
    for (int j = max(y - 1, 0); j <= min(y + 1, m - 1); ++j) {
      if (A[i][j] == '*') return 1;
    }
  }
  return 0;
}
int main() {
  int n, m;
  cin >> n >> m;
  char A[101][101];
  for (int i = 0; i < n; ++i)
    for (int j = 0; j < m; ++j) {
      cin >> A[i][j];
    }
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      if (A[i][j] == '.') {
        if (checkEmpty(A, i, j, n, m) == 1) {
          cout << "NO";
          return 0;
        }
      }
      if (A[i][j] == '*') {
        for (int x = max(i - 1, 0); x <= min(i + 1, n - 1); ++x) {
          for (int y = max(j - 1, 0); y <= min(j + 1, m - 1); ++y) {
            if (A[x][y] >= 48 && A[x][y] <= 56) --A[x][y];
          }
        }
      }
    }
  }
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      if (A[i][j] != '0' && A[i][j] != '.' && A[i][j] != '*') {
        cout << "NO";
        return 0;
      }
    }
  }
  cout << "YES";
}
