#include <bits/stdc++.h>
using namespace std;
const int xi[] = {1, 1, 1, 0, 0, -1, -1, -1};
const int yi[] = {-1, 0, 1, -1, 1, -1, 0, 1};
int main() {
  int m, n;
  cin >> m >> n;
  char g[m][n];
  for (int i = 0; i < m; i++)
    for (int j = 0; j < n; j++) cin >> g[i][j];
  int u, v;
  for (int i = 0; i < m; i++) {
    for (int j = 0; j < n; j++) {
      if (g[i][j] == '*') continue;
      int cnt = 0;
      for (int k = 0; k < 8; k++) {
        u = i + xi[k];
        v = j + yi[k];
        if (u >= 0 && u < m && v >= 0 && v < n && g[u][v] == '*') cnt++;
      }
      if (g[i][j] == '.') {
        if (cnt != 0) {
          cout << "NO\n";
          return 0;
        }
      } else {
        if (g[i][j] - '0' != cnt) {
          cout << "NO\n";
          return 0;
        }
      }
    }
  }
  cout << "YES\n";
  return 0;
}
