#include <bits/stdc++.h>
using namespace std;
bool check(vector<vector<char> > sweeper, int i, int j, int n, int m) {
  if (sweeper[i][j] == '*') return false;
  int x, y;
  if (sweeper[i][j] == '.') {
    for (x = i - 1; x <= i + 1; x++)
      for (y = j - 1; y <= j + 1; y++) {
        if (x != i || y != j) {
          if (x >= 0 && y >= 0 && x < n && y < m)
            if (sweeper[x][y] == '*') return true;
        }
      }
    return false;
  } else {
    int count_ = sweeper[i][j] - '0';
    for (x = i - 1; x <= i + 1; x++)
      for (y = j - 1; y <= j + 1; y++) {
        if (x != i || y != j)
          if (x >= 0 && y >= 0 && x < n && y < m)
            if (sweeper[x][y] == '*') count_--;
      }
    if (count_ == 0)
      return false;
    else
      return true;
  }
}
int main() {
  int n, m;
  cin >> n >> m;
  vector<vector<char> > sweeper(n, vector<char>(m));
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++) cin >> sweeper[i][j];
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++)
      if (check(sweeper, i, j, n, m)) {
        cout << "NO";
        return 0;
      }
  cout << "YES";
}
