#include <bits/stdc++.h>
using namespace std;
int dx[8] = {0, 0, 1, -1, -1, -1, 1, 1};
int dy[8] = {1, -1, 0, 0, 1, -1, 1, -1};
char s[111][111];
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) scanf("%s", s[i] + 1);
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++) {
      if (s[i][j] >= '1' && s[i][j] <= '8') {
        int cnt = 0;
        for (int k = 0; k < 8; k++) {
          int tx = i + dx[k];
          int ty = j + dy[k];
          if (tx >= 1 && tx <= n && ty >= 1 && ty <= m && s[tx][ty] == '*')
            cnt++;
        }
        if (cnt != s[i][j] - '0') return 0 * printf("NO\n");
      } else if (s[i][j] == '.') {
        for (int k = 0; k < 8; k++) {
          int tx = i + dx[k];
          int ty = j + dy[k];
          if (tx >= 1 && tx <= n && ty >= 1 && ty <= m && s[tx][ty] == '*')
            return 0 * printf("NO\n");
        }
      }
    }
  puts("YES");
}
