#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e2 + 50;
char maz[maxn][maxn];
int main() {
  int n, m;
  scanf("%d %d", &n, &m);
  for (int i = 1; i <= n; i++) scanf("%s", maz[i] + 1);
  int flag = 0;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      if (maz[i][j] == '*') continue;
      int cnt = 0;
      for (int p = -1; p <= 1; p++) {
        for (int q = -1; q <= 1; q++) {
          if (p == 0 && q == 0) continue;
          int tmpi = i + p;
          int tmpj = j + q;
          if (tmpi >= 1 && tmpi <= n && tmpj >= 1 && tmpj <= m) {
            if (maz[tmpi][tmpj] == '*') {
              cnt++;
            }
          }
        }
      }
      if ((cnt == 0 && maz[i][j] == '.') ||
          (cnt > 0 && maz[i][j] - '0' == cnt)) {
        continue;
      } else {
        flag = 1;
      }
    }
  }
  if (flag) {
    printf("NO\n");
  } else
    printf("YES\n");
}
