#include <bits/stdc++.h>
using namespace std;
const int64_t INF = 10000000000013LL;
int main() {
  long long n, i, j, val, f = 0, cnt = 0, m;
  cin >> n >> m;
  char a[n + 5][m + 5];
  for (i = 0; i <= n + 2; i++) {
    for (j = 0; j <= 2 + m; j++) {
      a[i][j] = '#';
    }
  }
  char x;
  for (i = 1; i <= n; i++) {
    for (j = 1; j <= m; j++) {
      cin >> x;
      a[i][j] = x;
    }
  }
  for (i = 1; i <= n; i++) {
    for (j = 1; j <= m; j++) {
      if (isdigit(a[i][j])) {
        val = a[i][j] - '0';
        cnt = 0;
        if (a[i][j - 1] == '*') cnt++;
        if (a[i - 1][j] == '*') cnt++;
        if (a[i - 1][j - 1] == '*') cnt++;
        if (a[i + 1][j] == '*') cnt++;
        if (a[i - 1][j + 1] == '*') cnt++;
        if (a[i + 1][j + 1] == '*') cnt++;
        if (a[i + 1][j - 1] == '*') cnt++;
        if (a[i][j + 1] == '*') cnt++;
        if (cnt != val) {
          f = 1;
        }
      }
      if (a[i][j] == '.') {
        if (a[i][j - 1] == '*') f = 1;
        if (a[i - 1][j] == '*') f = 1;
        if (a[i - 1][j - 1] == '*') f = 1;
        if (a[i + 1][j] == '*') f = 1;
        if (a[i - 1][j + 1] == '*') f = 1;
        if (a[i + 1][j + 1] == '*') f = 1;
        if (a[i + 1][j - 1] == '*') f = 1;
        if (a[i][j + 1] == '*') f = 1;
      }
    }
  }
  if (f)
    cout << "NO";
  else
    cout << "YES";
}
