#include <bits/stdc++.h>
using namespace std;
double Pi = 3.141592;
int val(char a) { return a - '0'; }
int main() {
  int n, m;
  cin >> n >> m;
  vector<vector<char>> F(n + 2, vector<char>(m + 2));
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) cin >> F[i][j];
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      if (isdigit(F[i][j])) {
        int cnt = 0;
        if (F[i - 1][j - 1] == '*') cnt++;
        if (F[i - 1][j] == '*') cnt++;
        if (F[i - 1][j + 1] == '*') cnt++;
        if (F[i][j - 1] == '*') cnt++;
        if (F[i][j + 1] == '*') cnt++;
        if (F[i + 1][j + 1] == '*') cnt++;
        if (F[i + 1][j] == '*') cnt++;
        if (F[i + 1][j - 1] == '*') cnt++;
        if (cnt != val(F[i][j])) {
          cout << "NO" << endl;
          return 0;
        }
      } else if (F[i][j] == '.') {
        int cnt = 0;
        if (F[i - 1][j - 1] == '*') cnt++;
        if (F[i - 1][j] == '*') cnt++;
        if (F[i - 1][j + 1] == '*') cnt++;
        if (F[i][j - 1] == '*') cnt++;
        if (F[i][j + 1] == '*') cnt++;
        if (F[i + 1][j + 1] == '*') cnt++;
        if (F[i + 1][j] == '*') cnt++;
        if (F[i + 1][j - 1] == '*') cnt++;
        if (cnt != 0) {
          cout << "NO" << endl;
          return 0;
        }
      }
    }
  }
  cout << "YES" << endl;
  return 0;
}
