#include <bits/stdc++.h>
using namespace std;
int main(void) {
  char s[131][131];
  int m, n;
  while (cin >> m >> n) {
    bool correct = true;
    memset(s, 0, sizeof(s));
    for (int i = 1; i <= m; i++) {
      for (int j = 1; j <= n; j++) {
        cin >> s[i][j];
      }
    }
    for (int i = 1; i <= m; i++) {
      for (int j = 1; j <= n; j++) {
        if (s[i][j] == '.') {
          int count = 0;
          for (int k = 1; k <= 3; k++) {
            for (int l = 1; l <= 3; l++) {
              if (s[i + k - 2][j + l - 2] == '*') {
                count += 1;
              }
            }
          }
          if (count != 0) {
            correct = false;
          }
        } else if (s[i][j] == '*') {
        } else {
          int count = 0;
          for (int k = 1; k <= 3; k++) {
            for (int l = 1; l <= 3; l++) {
              if (s[i + k - 2][j + l - 2] == '*') {
                count += 1;
              }
            }
          }
          if (count != s[i][j] - '0') {
            correct = false;
          }
        }
      }
    }
    if (correct) {
      printf("YES\n");
    } else {
      printf("NO\n");
    }
  }
  return 0;
}
