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