#include <bits/stdc++.h>
using namespace std;
int dx[8] = {0, 0, +1, -1, -1, +1, -1, +1};
int dy[8] = {+1, -1, 0, 0, -1, +1, +1, -1};
char arr[102][102];
int main() {
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      cin >> arr[i][j];
    }
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (arr[i][j] > '0' && arr[i][j] < '9') {
        int p = arr[i][j] - '0';
        int c = 0;
        for (int k = 0; k < 8; k++) {
          int x = dx[k] + i;
          int y = dy[k] + j;
          if (x >= 0 && y >= 0) {
            if (arr[x][y] == '*') {
              c++;
            }
          }
        }
        if (c > p || c < p) {
          cout << "NO" << endl;
          return 0;
        }
      } else if (arr[i][j] == '.') {
        int p = arr[i][j] - '0';
        int c = 0;
        for (int k = 0; k < 8; k++) {
          int x = dx[k] + i;
          int y = dy[k] + j;
          if (x >= 0 && y >= 0) {
            if (arr[x][y] == '*') {
              cout << "NO" << endl;
              return 0;
            }
          }
        }
      }
    }
  }
  cout << "YES" << endl;
}
