#include <bits/stdc++.h>
using namespace std;
const int INF = 1000000;
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  char a[102][102];
  int v[102][102];
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      scanf("%c", &a[i][j]);
      if (a[i][j] == '\n') {
        scanf("%c", &a[i][j]);
      }
      if (a[i][j] != '*' && a[i][j] != '.') {
        v[i][j] = a[i][j] - '0';
      } else if (a[i][j] == '*') {
        v[i][j] = INF;
      } else {
        v[i][j] = 0;
      }
    }
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      if (a[i][j] == '*') {
        for (int l = i - 1; l <= i + 1; l++)
          for (int r = j - 1; r <= j + 1; r++) {
            if (a[l][r] != '*') v[l][r]--;
          }
      }
    }
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      if (v[i][j] == 0 || v[i][j] == INF) {
        continue;
      } else {
        printf("NO");
        return 0;
      }
    }
  }
  printf("YES");
}
