#include <bits/stdc++.h>
using namespace std;
char s[123][123];
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  ;
  int n, m;
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) cin >> s[i][j];
  }
  int flag = 1;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      int cnt = 0;
      if (s[i][j] == '*') continue;
      if (s[i][j] == '.') {
        for (int k = i - 1; k <= i + 1; k++) {
          for (int l = j - 1; l <= j + 1; l++) {
            if (k == i && l == j) continue;
            if (s[k][l] == '*') cnt++;
          }
        }
        if (cnt != 0) {
          flag = 0;
        }
        continue;
      }
      for (int k = i - 1; k <= i + 1; k++) {
        for (int l = j - 1; l <= j + 1; l++) {
          if (k == i && l == j) continue;
          if (s[k][l] == '*') cnt++;
        }
      }
      int nn = s[i][j] - '0';
      if (cnt != nn) {
        flag = 0;
        break;
      }
    }
  }
  if (flag == 1)
    cout << "YES"
         << "\n";
  else
    cout << "NO"
         << "\n";
}
