#include <bits/stdc++.h>
using namespace std;
int n, m;
bool in_field(int i, int j) { return i >= 0 && i < n && j >= 0 && j < m; }
int main() {
  ios_base::sync_with_stdio(false);
  cin >> n >> m;
  vector<vector<char> > g(n, vector<char>(m));
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      cin >> g[i][j];
    }
  }
  int dx[] = {0, 0, -1, -1, -1, 1, 1, 1};
  int dy[] = {-1, 1, 0, -1, 1, 1, -1, 0};
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (g[i][j] == '*') continue;
      int cnt = 0;
      for (int k = 0; k < 8; k++) {
        int xx = dx[k] + i;
        int yy = dy[k] + j;
        if (in_field(xx, yy)) {
          if (g[xx][yy] == '*') {
            cnt++;
          }
        }
      }
      if (cnt != g[i][j] - '0' && g[i][j] != '.' || cnt > 0 && g[i][j] == '.') {
        cout << "NO";
        return 0;
      }
    }
  }
  cout << "YES";
  return 0;
}
