#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("O3")
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long n, m;
  cin >> n >> m;
  char a[n][m];
  char b[n][m];
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      cin >> b[i][j];
      a[i][j] = b[i][j];
    }
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (a[i][j] == '*') {
        if (i > 0 and j > 0 and a[i - 1][j - 1] != '*') {
          a[i - 1][j - 1]--;
        }
        if (j + 1 < m and i > 0 and a[i - 1][j + 1] != '*') {
          a[i - 1][j + 1]--;
        }
        if (i > 0 and a[i - 1][j] != '*') {
          a[i - 1][j]--;
        }
        if (j > 0 and a[i][j - 1] != '*') {
          a[i][j - 1]--;
        }
        if (j + 1 < m and a[i][j + 1] != '*') {
          a[i][j + 1]--;
        }
        if (i + 1 < n and j > 0 and a[i + 1][j - 1] != '*') {
          a[i + 1][j - 1]--;
        }
        if (i + 1 < n and a[i + 1][j] != '*') {
          a[i + 1][j]--;
        }
        if (i + 1 < n and j + 1 < m and 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 (b[i][j] == '.' and a[i][j] != '.') {
        cout << "no\n";
        return 0;
      } else if ((int)b[i][j] > 48 and (int) b[i][j] < 58 and
                 (int) a[i][j] != 48) {
        cout << "no\n";
        return 0;
      }
    }
  }
  cout << "yes";
  return 0;
}
