#include <bits/stdc++.h>
using namespace std;
int n, m, nieb;
int main() {
  cin >> m >> n;
  m++;
  n++;
  char mp[m + 1][n + 1];
  for (int i = 1; i < m; i++) {
    for (int k = 1; k < n; k++) {
      cin >> mp[i][k];
    }
  }
  for (int i = 1; i < m; i++) {
    for (int k = 1; k < n; k++) {
      nieb = 0;
      if (mp[i - 1][k] == '*') nieb++;
      if (mp[i + 1][k] == '*') nieb++;
      if (mp[i][k - 1] == '*') nieb++;
      if (mp[i][k + 1] == '*') nieb++;
      if (mp[i - 1][k - 1] == '*') nieb++;
      if (mp[i + 1][k + 1] == '*') nieb++;
      if (mp[i - 1][k + 1] == '*') nieb++;
      if (mp[i + 1][k - 1] == '*') nieb++;
      if ((nieb == 0 && mp[i][k] == '.') || mp[i][k] == '*') continue;
      if ((int)mp[i][k] - 48 != nieb) {
        cout << "NO";
        return 0;
      }
    }
  }
  cout << "YES";
}
