#include <bits/stdc++.h>
using namespace std;
char e[110][110];
int m, n;
int to[8][2] = {1, 0, 0, 1, -1, 0, 0, -1, 1, 1, -1, -1, 1, -1, -1, 1};
int SUM(int x, int y) {
  int sum = 0;
  for (int i = 0; i < 8; i++) {
    int dx = x + to[i][0];
    int dy = y + to[i][1];
    if (dx < 0 || dy < 0 || dx >= n || dy >= m) continue;
    if (e[dx][dy] == '*') sum++;
  }
  return sum;
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 0; i < n; i++) scanf("%s", e[i]);
  int flag = 1;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (e[i][j] == '*') continue;
      if (e[i][j] == '.') e[i][j] = '0';
      if (SUM(i, j) != e[i][j] - '0') {
        flag = 0;
        break;
      }
    }
    if (!flag) break;
  }
  if (flag)
    printf("YES\n");
  else
    printf("NO\n");
}
