#include <bits/stdc++.h>
using namespace std;
string s[105];
int a[105][105];
int rr[] = {-1, 0, 1, 1, 1, 0, -1, -1};
int cc[] = {1, 1, 1, 0, -1, -1, -1, 0};
class Node {
 public:
  int r, c;
};
int main(void) {
  int t, n, m, cs = 0, i, j, k, x, cnt, flag = 0, tmp;
  cin >> n >> m;
  Node u, v;
  int ur, uc, vr, vc;
  for (i = 0; i < n; i++) {
    cin >> s[i];
  }
  for (i = 0; i < n; i++) {
    for (j = 0; j < m; j++) {
      ur = i;
      uc = j;
      cnt = 0;
      for (k = 0; k < 8; k++) {
        vr = ur + rr[k];
        vc = uc + cc[k];
        if (vr >= 0 && vc >= 0 && vr < n && vc < m) {
          if (s[vr][vc] == '*') cnt++;
        }
      }
      tmp = s[i][j] - '0';
      if (s[i][j] == '.' && cnt == 0) continue;
      if (tmp == cnt) continue;
      if (s[i][j] == '*') continue;
      flag = 1;
      break;
    }
    if (flag) break;
  }
  if (flag)
    cout << "NO" << endl;
  else
    cout << "YES" << endl;
  return 0;
}
