#include <bits/stdc++.h>
using namespace std;
char g[1000][1000];
int main() {
  int R, C;
  scanf("%d %d", &R, &C);
  for (int i = 0; i < R; i++) scanf("%s", &g[i][0]);
  for (int r = 0; r < R; r++) {
    for (int c = 0; c < C; c++) {
      int cnt = 0;
      if (g[r][c] == '*') continue;
      for (int dr = -1; dr <= 1; dr++) {
        for (int dc = -1; dc <= 1; dc++) {
          if (r + dr < R && r + dr >= 0 && c + dc < C && c + dc >= 0) {
            if (g[r + dr][c + dc] == '*') cnt++;
          }
        }
      }
      if (cnt == 0 && g[r][c] == '.') continue;
      if (cnt == g[r][c] - '0') continue;
      printf("NO\n");
      return 0;
    }
  }
  printf("YES\n");
  return 0;
}
