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