#include <bits/stdc++.h>
using namespace std;
const signed long long int INF = 1e9 + 7;
const int N = 3e5 + 5;
char g[101][101];
int main() {
  int n, m;
  scanf("%d %d", &n, &m);
  for (int i(0); i < n; i++) {
    for (int j(0); j < m; j++) {
      cin >> g[i][j];
    }
  }
  bool ans = 1;
  for (int i(0); i < n; i++) {
    for (int j(0); j < m; j++) {
      if (g[i][j] >= '1' && g[i][j] <= '8') {
        int cnt = g[i][j] - '0';
        int bmb = 0;
        for (int di(-1); di <= 1; di++) {
          for (int dj(-1); dj <= 1; dj++) {
            if (di == 0 && dj == 0) continue;
            int ni = i + di;
            int nj = j + dj;
            if (ni < 0 || ni >= n || nj < 0 || nj >= m) continue;
            if (g[ni][nj] == '*') bmb++;
          }
        }
        if (bmb != cnt) ans = 0;
      } else {
        if (g[i][j] == '.') {
          int bmb = 0;
          for (int di(-1); di <= 1; di++) {
            for (int dj(-1); dj <= 1; dj++) {
              if (di == 0 && dj == 0) continue;
              int ni = i + di;
              int nj = j + dj;
              if (ni < 0 || ni >= n || nj < 0 || nj >= m) continue;
              if (g[ni][nj] == '*') bmb++;
            }
          }
          if (bmb != 0) ans = 0;
        }
      }
    }
  }
  if (ans == 0)
    printf("NO");
  else
    printf("YES");
  return 0;
}
