#include <bits/stdc++.h>
using namespace std;
int search(int i, int j, int array[100][100], int n, int m) {
  int l, p;
  int bom;
  bom = 0;
  for (l = i - 1; l <= i + 1; l++) {
    if (l < 0 || l >= n) continue;
    for (p = j - 1; p <= j + 1; p++) {
      if (p < 0 || p >= m) continue;
      if (array[l][p] == 11) bom++;
    }
  }
  return bom;
}
int main() {
  int i, j;
  int n, m;
  char c;
  int array[100][100];
  cin >> n >> m;
  for (i = 0; i < n; i++) {
    for (j = 0; j < m; j++) {
      cin >> c;
      if (c == '.') {
        array[i][j] = 10;
        continue;
      }
      if (c == '*') {
        array[i][j] = 11;
        continue;
      }
      array[i][j] = c - '0';
    }
  }
  for (i = 0; i < n; i++) {
    for (j = 0; j < m; j++) {
      if (array[i][j] == 10) {
        if (search(i, j, array, n, m) == 0) continue;
        cout << "NO" << endl;
        return 0;
      }
      if (array[i][j] == 11) {
        continue;
      }
      if (search(i, j, array, n, m) != array[i][j]) {
        cout << "NO" << endl;
        return 0;
      }
    }
  }
  cout << "YES" << endl;
  return 0;
}
