#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  int m, n;
  cin >> n >> m;
  char mat[n][m];
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      cin >> mat[i][j];
    }
  }
  bool ok = true;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      int num;
      if (mat[i][j] == '*') continue;
      if (mat[i][j] == '.') {
        num = 0;
      } else
        num = mat[i][j] - 48;
      int star = 0;
      if (i > 0 && j > 0) {
        if (mat[i - 1][j - 1] == '*') star++;
      }
      if (j > 0) {
        if (mat[i][j - 1] == '*') star++;
      }
      if (i < n - 1 && j > 0) {
        if (mat[i + 1][j - 1] == '*') star++;
      }
      if (i < n - 1) {
        if (mat[i + 1][j] == '*') star++;
      }
      if (i < n - 1 && j < m - 1) {
        if (mat[i + 1][j + 1] == '*') star++;
      }
      if (j < m - 1) {
        if (mat[i][j + 1] == '*') star++;
      }
      if (i > 0 && j < m - 1) {
        if (mat[i - 1][j + 1] == '*') star++;
      }
      if (i > 0) {
        if (mat[i - 1][j] == '*') star++;
      }
      if (num != star) {
        ok = false;
        break;
      }
    }
    if (!ok) break;
  }
  if (ok)
    cout << "YES\n";
  else
    cout << "NO\n";
  return 0;
}
