#include <bits/stdc++.h>
using namespace std;
char ara[101][101];
int fun(int i, int j, int n, int m) {
  int ct = 0;
  if (i - 1 >= 0 && j - 1 >= 0 && ara[i - 1][j - 1] == '*') ct++;
  if (i - 1 >= 0 && ara[i - 1][j] == '*') ct++;
  if (i - 1 >= 0 && j + 1 < m && ara[i - 1][j + 1] == '*') ct++;
  if (j - 1 >= 0 && ara[i][j - 1] == '*') ct++;
  if (j + 1 < m && ara[i][j + 1] == '*') ct++;
  if (i + 1 < n && j - 1 >= 0 && ara[i + 1][j - 1] == '*') ct++;
  if (i + 1 < n && ara[i + 1][j] == '*') ct++;
  if (i + 1 < n && j + 1 < m && ara[i + 1][j + 1] == '*') ct++;
  return ct;
}
int main() {
  int n, m, ct, i, j, test;
  cin >> n >> m;
  for (i = 0; i < n; i++) {
    for (j = 0; j < m; j++) {
      cin >> ara[i][j];
    }
  }
  for (i = 0; i < n; i++) {
    for (j = 0; j < m; j++) {
      if (ara[i][j] == '*') continue;
      if (ara[i][j] != '.') {
        ct = fun(i, j, n, m);
        test = ara[i][j] - '0';
        if (test != ct) {
          cout << "NO" << endl;
          return 0;
        }
      }
      if (ara[i][j] == '.' && fun(i, j, n, m) != 0) {
        cout << "NO" << endl;
        return 0;
      }
    }
  }
  cout << "YES" << endl;
  return 0;
}
