#include <bits/stdc++.h>
using namespace std;
const int nn = 108;
const int px[] = {-1, 0, 1, -1, 1, -1, 0, 1};
const int py[] = {-1, -1, -1, 0, 0, 1, 1, 1};
char s[nn][nn];
int n, m;
char calc(int x, int y) {
  int res = 0;
  for (int i = 0; i < 8; i++) {
    int u = x + px[i];
    int v = y + py[i];
    if (u > 0 && u <= n && v > 0 && v <= m && s[u][v] == '*') res++;
  }
  if (res == 0)
    return '.';
  else
    return res + 48;
}
int main() {
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    cin >> s[i] + 1;
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      if (s[i][j] == '*') continue;
      if (calc(i, j) != s[i][j]) {
        cout << "NO";
        return 0;
      }
    }
  }
  cout << "YES";
}
