#include <bits/stdc++.h>
using namespace std;
long long n, m;
bool safe(long long x, long long y) {
  return (x < n && x >= 0 && y < m && y >= 0);
}
long long dx[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
long long dy[8] = {0, 1, 1, 1, 0, -1, -1, -1};
int main() {
  std::ios::sync_with_stdio(false);
  cin.tie(0);
  long long i, j, k;
  cin >> n >> m;
  char a[n][m];
  for (i = 0; i < n; i++) {
    for (j = 0; j < m; j++) {
      cin >> a[i][j];
    }
  }
  bool fl = true;
  for (i = 0; i < n; i++) {
    for (j = 0; j < m; j++) {
      if (a[i][j] == '.') {
        for (long long k = 0; k < 8; k++) {
          long long x = i + dx[k], y = j + dy[k];
          if (safe(x, y) && a[x][y] == '*') fl = false;
        }
      } else if (a[i][j] != '*') {
        long long c = (long long)(a[i][j] - '0');
        for (k = 0; k < 8; k++) {
          long long x = i + dx[k], y = j + dy[k];
          if (safe(x, y) && a[x][y] == '*') {
            c--;
          }
        }
        if (c != 0) fl = false;
      }
    }
  }
  if (fl)
    cout << "YES";
  else
    cout << "NO";
  return 0;
}
