#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e18 + 7;
const double eps = 1e-5;
const int maxn = 1e2 + 7;
char a[105][105], b[105][105];
int n, m;
bool check(int i, int j) {
  if (i >= 1 && i <= n && j >= 1 && j <= m && b[i][j] != '*') return true;
  return false;
}
void cpy(int i, int j) {
  if (check(i - 1, j - 1)) b[i - 1][j - 1]++;
  if (check(i - 1, j)) b[i - 1][j]++;
  if (check(i - 1, j + 1)) b[i - 1][j + 1]++;
  if (check(i, j - 1)) b[i][j - 1]++;
  if (check(i, j + 1)) b[i][j + 1]++;
  if (check(i + 1, j - 1)) b[i + 1][j - 1]++;
  if (check(i + 1, j)) b[i + 1][j]++;
  if (check(i + 1, j + 1)) b[i + 1][j + 1]++;
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) {
    scanf("%s", a[i] + 1);
    for (int j = 1; j <= m; j++) {
      b[i][j] = '0';
      if (a[i][j] == '*') b[i][j] = '*';
    }
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      if (a[i][j] == '.')
        a[i][j] = '0';
      else if (a[i][j] == '*') {
        cpy(i, j);
      }
    }
  }
  bool flag = 1;
  for (int i = 1; i <= n; i++) {
    if (strcmp(a[i] + 1, b[i] + 1)) {
      flag = 0;
      break;
    }
  }
  if (flag)
    cout << "YES";
  else
    cout << "NO";
  return 0;
}
