#include <bits/stdc++.h>
using namespace std;
int n, m, a[105][105];
char c[105][105];
bool flg = true;
inline int rd() {
  char c = ' ';
  int x = 0, f = 1;
  while (c > '9' || c < '0') {
    if (c == '-') f = -1;
    c = getchar();
  }
  while (c <= '9' && c >= '0') x = x * 10 + c - '0', c = getchar();
  return x * f;
}
int main() {
  n = rd();
  m = rd();
  for (int i = 1; i <= n; i++) {
    scanf("%s", c[i] + 1);
    for (int j = 1; j <= m; j++) {
      if (c[i][j] == '*') a[i][j] = -1;
      if (c[i][j] >= '0' && c[i][j] <= '9') a[i][j] = c[i][j] - '0';
    }
  }
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++) {
      if (a[i][j] == -1) continue;
      int cnt = 0;
      if (a[i - 1][j] == -1) cnt++;
      if (a[i][j - 1] == -1) cnt++;
      if (a[i + 1][j] == -1) cnt++;
      if (a[i][j + 1] == -1) cnt++;
      if (a[i + 1][j + 1] == -1) cnt++;
      if (a[i - 1][j + 1] == -1) cnt++;
      if (a[i - 1][j - 1] == -1) cnt++;
      if (a[i + 1][j - 1] == -1) cnt++;
      if (cnt != a[i][j]) {
        flg = false;
        break;
      }
      if (cnt == 0 && a[i][j] > 0) {
        flg = false;
        break;
      }
    }
  if (!flg)
    printf("NO");
  else
    printf("YES");
  return 0;
}
