#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int n, m;
bool checkBound(int y, int x) { return (0 <= y && y < n) && (0 <= x && x < m); }
int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  char field[107][107];
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      cin >> field[i][j];
    }
  }
  bool f = true;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      int around = 0;
      for (int dx = -1; dx <= 1; dx++) {
        for (int dy = -1; dy <= 1; dy++) {
          if (dx == 0 && dy == 0) continue;
          int ny = i + dy;
          int nx = j + dx;
          if (checkBound(ny, nx) && field[ny][nx] == '*') {
            around++;
          }
        }
      }
      if (field[i][j] == '.') {
        if (around != 0) {
          f = false;
        }
      } else if (isdigit(field[i][j])) {
        if (around != field[i][j] - '0') {
          f = false;
        }
      }
    }
  }
  if (f) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  return 0;
}
