#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long n, m, i, j;
  cin >> n >> m;
  char a[200][200];
  for (i = 1; i <= n; i++)
    for (j = 1; j <= m; j++) cin >> a[i][j];
  vector<vector<long long> > b(200, vector<long long>(200));
  for (i = 1; i <= n; i++) {
    for (j = 1; j <= m; j++) {
      if (a[i][j] == '*') {
        b[i][j + 1]++;
        b[i][j - 1]++;
        b[i + 1][j]++;
        b[i - 1][j]++;
        b[i + 1][j + 1]++;
        b[i + 1][j - 1]++;
        b[i - 1][j + 1]++;
        b[i - 1][j - 1]++;
      }
    }
  }
  char c[200][200];
  for (i = 1; i <= n; i++) {
    for (j = 1; j <= m; j++) {
      if (a[i][j] == '*')
        c[i][j] = a[i][j];
      else if (b[i][j] == 0)
        c[i][j] = '.';
      else
        c[i][j] = b[i][j] += '0';
    }
  }
  for (i = 1; i <= n; i++) {
    for (j = 1; j <= m; j++) {
      if (a[i][j] != c[i][j]) {
        cout << "NO" << endl;
        return 0;
      }
    }
  }
  cout << "YES" << endl;
}
