#include <bits/stdc++.h>
using namespace std;
int dx[] = {0, 0, 1, -1, 1, 1, -1, -1};
int dy[] = {1, -1, 0, 0, 1, -1, 1, -1};
char mat[105][105];
int n, m;
int main() {
  scanf("%d %d", &n, &m);
  for (int i = 0; i < n; i++) {
    scanf(" %s", mat[i]);
  }
  int flag = 0;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (mat[i][j] == '*') continue;
      int cnt = 0;
      for (int k = 0; k < 8; k++) {
        if (i + dx[k] < 0 || j + dy[k] < 0 || i + dx[k] >= n || j + dy[k] >= m)
          continue;
        if (mat[i + dx[k]][j + dy[k]] == '*') cnt++;
      }
      int koto;
      if (mat[i][j] == '.')
        koto = 0;
      else
        koto = mat[i][j] - '0';
      if (cnt != koto) flag = 1;
    }
  }
  if (flag == 1) {
    cout << "NO" << endl;
  } else
    cout << "YES" << endl;
}
