#include <bits/stdc++.h>
using namespace std;
const int N = 1e3;
int n, m, cnt;
char a[N][N];
int xr[] = {-1, 0, 1, 0, -1, -1, 1, 1};
int xl[] = {0, -1, 0, 1, -1, 1, -1, 1};
int main() {
  cin >> n >> m;
  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++) {
      for (int h = 0; h < 8; h++) {
        if (a[i + xr[h]][j + xl[h]] == '*') {
          cnt++;
        }
      }
      if (a[i][j] - '0' != cnt and a[i][j] != '*' and a[i][j] != '.') {
        cout << "NO";
        return 0;
      }
      if (a[i][j] == '.' and cnt != 0) {
        cout << "NO";
        return 0;
      }
      cnt = 0;
    }
  }
  cout << "YES";
}
