#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  char a[n + 2][m + 2];
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      cin >> a[i][j];
      if (a[i][j] == '.') a[i][j] = '0';
    }
  }
  for (int i = 0; i <= n + 1; i++) {
    a[i][0] = '.';
    a[i][m + 1] = '.';
  }
  for (int i = 0; i <= m + 1; i++) {
    a[0][i] = '.';
    a[n + 1][i] = '.';
  }
  bool correct = true;
  int num_bombs = 0;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      if (isdigit(a[i][j])) {
        num_bombs = 0;
        int t[3] = {-1, 0, 1};
        for (int k = 0; k < 3; k++) {
          for (int q = 0; q < 3; q++) {
            num_bombs += (a[i + t[k]][j + t[q]] == '*');
          }
        }
        if (int(a[i][j]) - 48 != num_bombs) {
          correct = false;
          cout << "No\n";
          return 0;
        }
      }
    }
  }
  cout << "Yes";
}
