#include <bits/stdc++.h>
using namespace std;
char a[120][120];
int dx[] = {0, 0, 1, 1, 1, -1, -1, -1};
int dy[] = {1, -1, 0, 1, -1, 0, 1, -1};
bool flag = false;
int main() {
  int n, m;
  cin >> n >> m;
  for (int i = 1; i <= n; i++) scanf("%s", a[i] + 1);
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++) {
      if (a[i][j] == '.') {
        for (int ii = 0; ii < 8; ii++) {
          int xx = i + dx[ii];
          int yy = j + dy[ii];
          if (a[xx][yy] == '*') {
            cout << "NO";
            return 0;
          }
        }
      } else if (a[i][j] >= '1' && a[i][j] <= '9') {
        int cnt = a[i][j] - '0';
        for (int ii = 0; ii < 8; ii++) {
          int xx = i + dx[ii];
          int yy = j + dy[ii];
          if (a[xx][yy] == '*') cnt--;
        }
        if (cnt != 0) {
          cout << "NO";
          return 0;
        }
      }
    }
  cout << "YES";
  return 0;
}
