#include <bits/stdc++.h>
using namespace std;
string line;
vector<string> mine;
int m, n;
void creat() {
  int i;
  getline(cin, line);
  line.clear();
  for (i = 1; i <= m; i++) {
    line.clear();
    getline(cin, line);
    mine.push_back(line);
  }
}
void check() {
  int i, j, x, y, cnt;
  for (i = 0; i < m; i++) {
    for (j = 0; j < n; j++) {
      for (x = -1, cnt = 0; x <= 1; x++) {
        for (y = -1; y <= 1; y++) {
          if (x == 0 && y == 0) continue;
          if (-1 < i + x && i + x < m && -1 < j + y && j + y < n) {
            if (mine[i + x][j + y] == '*') cnt++;
          } else
            continue;
        }
      }
      if (mine[i][j] >= 49 && mine[i][j] <= 57) {
        if (cnt == mine[i][j] - 48)
          continue;
        else {
          cout << "No";
          return;
        }
      }
      if (mine[i][j] == '.') {
        if (cnt == 0) {
          continue;
        } else {
          cout << "No";
          return;
        }
      }
      if (mine[i][j] == '*') {
        continue;
      }
    }
  }
  if (i == m && j == n) {
    cout << "Yes";
  }
}
int main() {
  cin >> m >> n;
  creat();
  check();
}
