#include <bits/stdc++.h>
using namespace std;
char c[105][105], ans[105][105];
int dx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
int dy[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
int main() {
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      cin >> c[i][j];
    }
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      int cnt = 0;
      if (c[i][j] == '*') {
        ans[i][j] = '*';
        continue;
      }
      for (int k = 0; k < 8; k++) {
        if (i + dy[k] < 0 || i + dy[k] >= n || j + dx[k] < 0 || j + dx[k] >= m)
          continue;
        cnt += (c[i + dy[k]][j + dx[k]] == '*');
      }
      ans[i][j] = (cnt == 0 ? '.' : cnt + '0');
    }
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (ans[i][j] != c[i][j]) {
        cout << "NO\n";
        return 0;
      }
    }
  }
  cout << "YES\n";
}
