#include <bits/stdc++.h>
using namespace std;
const size_t SIZE = 102;
int n, m;
char a[SIZE][SIZE];
int amount[SIZE][SIZE];
int main() {
  cin.tie();
  ios_base::sync_with_stdio(0);
  cin >> n >> m;
  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j <= m; ++j) {
      cin >> a[i][j];
      if (a[i][j] == '*') {
        for (int x = i - 1; x <= i + 1; ++x) {
          for (int y = j - 1; y <= j + 1; ++y) {
            ++amount[x][y];
          }
        }
      }
    }
  }
  bool ok = true;
  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j <= m; ++j) {
      if (a[i][j] != '.' && a[i][j] != '*') {
        if (int(a[i][j] - '0') != amount[i][j]) {
          ok = false;
          break;
        }
      }
      if (a[i][j] == '.' && amount[i][j] != 0) {
        ok = false;
        break;
      }
    }
    if (!ok) {
      break;
    }
  }
  if (ok) {
    cout << "YES";
  } else {
    cout << "NO";
  }
  return 0;
}
