#include <bits/stdc++.h>
using namespace std;
char d[110][110];
int n, m, a[110][110], mi[110][110], key = 1;
int dc[8] = {-1, 0, 1, -1, 1, -1, 0, 1};
int dr[8] = {-1, -1, -1, 0, 0, 1, 1, 1};
int main() {
  scanf("%d %d", &n, &m);
  for (int i = 1; i <= n; i++) {
    scanf("%s", d[i] + 1);
    for (int j = 1; j <= m; j++) {
      if (d[i][j] == '*')
        mi[i][j] = 1, a[i][j] = -1;
      else if (d[i][j] == '.')
        a[i][j] = 0;
      else
        a[i][j] = d[i][j] - '0';
    }
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      if (a[i][j] == -1) continue;
      int sum = 0;
      for (int k = 0; k < 8; k++) {
        if (mi[i + dc[k]][j + dr[k]] == 1) sum++;
      }
      if (a[i][j] != sum) key = 0;
    }
  }
  if (key == 1)
    printf("YES");
  else
    printf("NO");
}
