#include <bits/stdc++.h>
using namespace std;
const int maxn = 100 + 100;
int dic[10][5] = {{1, 0},   {0, 1}, {-1, 0}, {0, -1},
                  {-1, -1}, {1, 1}, {1, -1}, {-1, 1}};
char cc[maxn][maxn];
int n, m;
int main() {
  scanf("%d%d", &n, &m);
  getchar();
  for (int i = 0; i < n; i++) {
    scanf("%s", cc[i]);
  }
  int flag = 0;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++)
      if (cc[i][j] != '*') {
        int ans = 0;
        for (int k = 0; k < 8; k++) {
          int x = i + dic[k][0];
          int y = j + dic[k][1];
          if (x >= 0 && x < n && y >= 0 && y < m) {
            if (cc[x][y] == '*') {
              ans++;
            }
          }
        }
        int pp;
        if (cc[i][j] == '.')
          pp = 0;
        else
          pp = cc[i][j] - '0';
        if (pp != ans) {
          flag = 1;
          break;
        }
      }
    if (flag) break;
  }
  if (flag)
    printf("NO\n");
  else
    printf("YES\n");
  return 0;
}
