#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
const double PI = 2 * acos(0.0);
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n, m;
  cin >> n >> m;
  char given[n][m];
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      cin >> given[i][j];
    }
  }
  bool ok = true;
  int l, r, u, d, bombs;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (given[i][j] != '*') {
        l = max(0, j - 1);
        r = min(m - 1, j + 1);
        u = max(0, i - 1);
        d = min(n - 1, i + 1);
        bombs = 0;
        for (int row = u; row <= d; row++) {
          for (int col = l; col <= r; col++) {
            if (given[row][col] == '*') {
              bombs += 1;
            }
          }
        }
        if (given[i][j] == '.') {
          if (bombs != 0) {
            ok = false;
            break;
          }
        } else if ((int)given[i][j] - 48 != bombs) {
          ok = false;
          break;
        }
      }
    }
    if (!ok) {
      break;
    }
  }
  if (ok) {
    cout << "YES"
         << "\n";
  } else {
    cout << "NO"
         << "\n";
  }
  return 0;
}
