#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  char grid[n][m];
  for (int i = 0; i < n; i++) cin >> grid[i];
  int dx[8] = {-1, -1, -1, 0, 0, 1, 1, 1};
  int dy[8] = {-1, 0, 1, -1, 1, -1, 0, 1};
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      int c = 0;
      for (int d = 0; d < 8; d++) {
        int rw = i + dx[d], cl = j + dy[d];
        if (rw >= 0 && rw < n && cl >= 0 && cl < m) {
          if (grid[rw][cl] == '*') c++;
        }
      }
      if (grid[i][j] == '.') {
        if (c != 0) {
          cout << "NO" << endl;
          return 0;
        }
      } else if (grid[i][j] != '*') {
        int xx = (char)grid[i][j] - '0';
        if (xx != c) {
          cout << "NO" << endl;
          return 0;
        }
      }
    }
  }
  cout << "YES" << endl;
  return 0;
}
