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