#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const long long mod = 1e9 + 7;
const int N = 1e2 + 10;
char str[N][N];
char ss[N][N];
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) scanf("%s", str[i] + 1);
  for (int i = 0; i <= n + 1; i++)
    for (int j = 0; j <= m + 1; j++) ss[i][j] = '0';
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      if (str[i][j] == '*') {
        ss[i][j] = '*';
        for (int k = -1; k <= 1; k++)
          for (int t = -1; t <= 1; t++) {
            if (k == 0 && t == 0) continue;
            if (ss[i + k][j + t] == '*') continue;
            ss[i + k][j + t] += 1;
          }
      }
    }
  }
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++) {
      if (ss[i][j] == '0') ss[i][j] = '.';
      if (ss[i][j] != str[i][j]) {
        printf("NO");
        return 0;
      }
    }
  printf("YES");
  return 0;
}
