#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  char arr[102][102];
  for (int i = 0; i <= n + 1; i++) {
    for (int j = 0; j <= m + 1; j++) {
      arr[i][j] = '0';
    }
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      cin >> arr[i][j];
    }
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      if (arr[i][j] == '.') {
        if ((arr[i - 1][j - 1] == '*') || (arr[i - 1][j] == '*') ||
            (arr[i - 1][j + 1] == '*') || (arr[i][j + 1] == '*') ||
            (arr[i + 1][j + 1] == '*') || (arr[i + 1][j] == '*') ||
            (arr[i + 1][j - 1] == '*') || (arr[i][j - 1] == '*')) {
          cout << "NO";
          return 0;
        }
      }
      for (int k = 1; k <= 8; k++) {
        if (arr[i][j] == k + '0') {
          int zv = 0;
          if (arr[i - 1][j - 1] == '*') {
            zv++;
          }
          if (arr[i - 1][j] == '*') {
            zv++;
          }
          if (arr[i - 1][j + 1] == '*') {
            zv++;
          }
          if (arr[i][j + 1] == '*') {
            zv++;
          }
          if (arr[i + 1][j + 1] == '*') {
            zv++;
          }
          if (arr[i + 1][j] == '*') {
            zv++;
          }
          if (arr[i + 1][j - 1] == '*') {
            zv++;
          }
          if (arr[i][j - 1] == '*') {
            zv++;
          }
          if (zv != k) {
            cout << "NO";
            return 0;
          }
        }
      }
    }
  }
  cout << "YES";
  return 0;
}
