#include <bits/stdc++.h>
using namespace std;
char s[105][105];
int n, m;
int x[] = {-1, -1, -1, 0, 0, 1, 1, 1};
int y[] = {-1, 0, 1, -1, 1, -1, 0, 1};
bool isafe(int i, int j) {
  if (i >= 0 && i < n && j >= 0 && j < m) return true;
  return false;
}
int check(int i, int j) {
  int k, l, s1 = 0;
  for (int u = 0; u < 8; u++) {
    k = i + x[u];
    l = j + y[u];
    if (isafe(k, l) && s[k][l] == '*') {
      s1++;
    }
  }
  return s1;
}
bool check1(int i, int j) {
  int k, l, s1 = 0;
  for (int u = 0; u < 8; u++) {
    k = i + x[u];
    l = j + y[u];
    if (isafe(k, l) && s[k][l] == '*') return false;
  }
  return true;
}
int main() {
  cin >> n >> m;
  for (int i = 0; i < n; i++) cin >> s[i];
  bool f = true;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (s[i][j] >= '0' && s[i][j] <= '8') {
        int u = s[i][j] - '0';
        int v = check(i, j);
        if (u != v) {
          cout << "NO" << endl;
          return 0;
        }
      }
      if (s[i][j] == '.') {
        if (!check1(i, j)) {
          cout << "NO" << endl;
          return 0;
        }
      }
    }
  }
  cout << "YES" << endl;
}
