#include <bits/stdc++.h>
using namespace std;
int mx[8] = {-1, 0, 1, -1, 1, -1, 0, 1}, my[8] = {-1, -1, -1, 0, 0, 1, 1, 1};
int main() {
  ios::sync_with_stdio(false);
  int n, m;
  cin >> n >> m;
  char a[n + 2][m + 2];
  memset(a, 0, sizeof a);
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++) {
      cin >> a[i][j];
    }
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++) {
      if (a[i][j] != '*') {
        int cnt = 0;
        for (int k = 0; k <= 7; k++) {
          if (a[i + mx[k]][j + my[k]] == '*') cnt++;
        }
        if (!(cnt == 0 && a[i][j] == '.' || cnt > 0 && a[i][j] - '0' == cnt)) {
          cout << "NO" << endl;
          return 0;
        }
      }
    }
  cout << "YES" << endl;
  return 0;
}
