#include <bits/stdc++.h>
using namespace std;
bool isSafe(const int n, const int m, const int row, const int col) {
  return row >= 0 && row < n && col >= 0 && col < m;
}
int main(int argc, char* argv[]) {
  int n, m;
  static pair<int, int> pos[] = {{-1, -1}, {-1, 0}, {-1, 1}, {0, -1}, {0, 0},
                                 {0, 1},   {1, -1}, {1, 0},  {1, 1}};
  int posLen = sizeof(pos) / sizeof(pos[0]);
  cin >> n >> m;
  vector<string> vec(n);
  for (int i = 0; i < n; i++) {
    cin >> vec[i];
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      int count = 0;
      if (vec[i][j] == '*') {
        continue;
      }
      for (int k = 0; k < posLen; k++) {
        if (isSafe(n, m, i + pos[k].first, j + pos[k].second) &&
            vec[i + pos[k].first][j + pos[k].second] == '*') {
          count++;
        }
      }
      if ((count == 0 && vec[i][j] != '.') ||
          (count != 0 && count != vec[i][j] - '0')) {
        cout << "NO";
        return 0;
      }
    }
  }
  cout << "YES";
  return 0;
}
