#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  char a[n][m];
  for (int i = 0; i < n; i++) cin >> a[i];
  int f = 1;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (a[i][j] != '*') {
        int sum = 0, t;
        if (a[i][j] >= '1' && a[i][j] <= '8')
          t = a[i][j] - '0';
        else
          t = 0;
        if (i > 0 && j > 0 && a[i - 1][j - 1] == '*') sum++;
        if (i > 0 && a[i - 1][j] == '*') sum++;
        if (i > 0 && j < m - 1 && a[i - 1][j + 1] == '*') sum++;
        if (j > 0 && a[i][j - 1] == '*') sum++;
        if (j < m - 1 && a[i][j + 1] == '*') sum++;
        if (i < n - 1 && j > 0 && a[i + 1][j - 1] == '*') sum++;
        if (i < n - 1 && a[i + 1][j] == '*') sum++;
        if (i < n - 1 && j < m - 1 && a[i + 1][j + 1] == '*') sum++;
        if (sum != t) {
          f = 0;
          break;
        }
      }
    }
    if (f == 0) break;
  }
  if (f == 0)
    cout << "NO" << endl;
  else
    cout << "YES" << endl;
}
