#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  int n, m;
  cin >> n >> m;
  vector<vector<char>> v(n + 2, vector<char>(m + 2, '0'));
  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j <= m; ++j) {
      cin >> v[i][j];
    }
  }
  bool f = 0;
  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j <= m; ++j) {
      int tmp = 0;
      if (v[i][j - 1] == '*') {
        tmp++;
      }
      if (v[i][j + 1] == '*') {
        tmp++;
      }
      if (v[i - 1][j] == '*') {
        tmp++;
      }
      if (v[i - 1][j - 1] == '*') {
        tmp++;
      }
      if (v[i - 1][j + 1] == '*') {
        tmp++;
      }
      if (v[i + 1][j] == '*') {
        tmp++;
      }
      if (v[i + 1][j - 1] == '*') {
        tmp++;
      }
      if (v[i + 1][j + 1] == '*') {
        tmp++;
      }
      if (v[i][j] == '.' && tmp != 0) f = 1;
      if (v[i][j] >= '1' && v[i][j] <= '8' && v[i][j] - '0' != tmp) f = 1;
    }
  }
  cout << (!f ? "YES" : "NO");
}
