#include <bits/stdc++.h>
using namespace std;
int check_validity(vector<vector<char>> field, int row, int col, int mxR,
                   int mxC) {
  int count = 0;
  int data = field[row][col];
  for (int r = row - 1; r <= row + 1; ++r) {
    for (int c = col - 1; c <= col + 1; ++c) {
      if (r >= 0 && r <= mxR && c >= 0 && c <= mxC) {
        if (field[r][c] == '*') count++;
      }
    }
  }
  return count;
}
int main() {
  int n, m;
  cin >> n >> m;
  vector<vector<char>> field(n, vector<char>());
  char data;
  for (int row = 0; row < n; ++row) {
    for (int col = 0; col < m; ++col) {
      cin >> data;
      field[row].push_back(data);
    }
  }
  bool valid = true;
  for (int row = 0; row < n; ++row) {
    for (int col = 0; col < m; ++col) {
      int count = check_validity(field, row, col, n - 1, m - 1);
      if (field[row][col] >= '0' && field[row][col] <= '8') {
        if (count != (field[row][col] - '0')) valid = false;
      } else if (field[row][col] == '.') {
        if (count != 0) valid = false;
      }
    }
  }
  if (valid)
    cout << "YES" << endl;
  else
    cout << "NO" << endl;
  return 0;
}
