#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m, count;
  char c;
  cin >> n >> m;
  char a[n + 2][m + 2];
  for (int i = 0; i < n + 2; i++) {
    a[i][0] = '0';
    a[i][m + 1] = '0';
  }
  for (int i = 0; i < m + 2; i++) {
    a[0][i] = '0';
    a[n + 1][i] = '0';
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      cin >> a[i][j];
      if (a[i][j] == '.') {
        a[i][j] = '0';
      }
    }
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      if (a[i][j] != '*') {
        count = 0;
        for (int k = i - 1; k <= i + 1; k++) {
          for (int l = j - 1; l <= j + 1; l++) {
            if (a[k][l] == '*') {
              count++;
            }
          }
        }
        if (count != (a[i][j] - 48)) {
          cout << "NO";
          return (0);
        }
      }
    }
  }
  cout << "YES";
}
