#include <bits/stdc++.h>
using namespace std;
const int N = (int)(1 * 1e6 + 10);
int bit[N];
void update(int i, int add) {
  while (i > 0 && i < N) {
    bit[i] += add;
    i += (i & (-i));
  }
}
int sum1(int i) {
  int s = 0;
  while (i > 0) {
    s += bit[i];
    i = i - (i & (-i));
  }
  return s;
}
std::map<long long, long long> has;
set<long long> s1;
long long n;
std::vector<string> v1(2);
bool notok(long long val, long long i, long long j) {
  long long c = 0;
  if (v1[i][j + 1] == '*') c++;
  if (v1[i][j - 1] == '*') c++;
  if (v1[i + 1][j + 1] == '*') c++;
  if (v1[i + 1][j - 1] == '*') c++;
  if (v1[i + 1][j] == '*') c++;
  if (v1[i - 1][j] == '*') c++;
  if (v1[i - 1][j + 1] == '*') c++;
  if (v1[i - 1][j - 1] == '*') c++;
  return c != val;
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long h, m, q, H, D, C;
  cin >> n >> m;
  v1.resize(n + 2);
  string r = "";
  for (long long i = 0; i < m + 2; i++) {
    r += '0';
  }
  v1[0] = r;
  string s;
  for (long long i = 1; i <= n; i++) {
    cin >> s;
    s = '0' + s + '0';
    v1[i] = s;
  }
  v1[n + 1] = r;
  for (long long i = 0; i <= n + 1; i++) {
    for (long long j = 0; j < v1[i].size(); j++) {
      if (v1[i][j] == '.') v1[i][j] = '0';
    }
  }
  for (long long i = 1; i <= n; i++) {
    for (long long j = 1; j <= m; j++) {
      if (v1[i][j] == '*') continue;
      if (notok(int(v1[i][j] - '0'), i, j)) {
        return cout << "NO", 0;
      }
    }
  }
  cout << "YES";
  return 0;
}
