#include <bits/stdc++.h>
using namespace std;
const long double eps = 1e-12;
unsigned long long gcd(unsigned long long a, unsigned long long b) {
  return b ? gcd(b, a % b) : a;
}
long long sqr(long long a) { return a * a; }
struct point {
  long long x, y;
};
struct straight {
  long long a, b, c;
};
long long n, m;
long long a[110][110];
bool f = 1;
void chnull(long long i, long long j) {
  if (a[i][j + 1] == -1 || a[i][j - 1] == -1 || a[i - 1][j] == -1 ||
      a[i - 1][j - 1] == -1 || a[i - 1][j + 1] == -1 || a[i + 1][j - 1] == -1 ||
      a[i + 1][j + 1] == -1 || a[i + 1][j] == -1)
    f = 0;
  return;
}
void chdef(long long i, long long j) {
  long long k = 0;
  if (a[i - 1][j] == -1) k++;
  if (a[i - 1][j - 1] == -1) k++;
  if (a[i - 1][j + 1] == -1) k++;
  if (a[i + 1][j - 1] == -1) k++;
  if (a[i + 1][j + 1] == -1) k++;
  if (a[i + 1][j] == -1) k++;
  if (a[i][j + 1] == -1) k++;
  if (a[i][j - 1] == -1) k++;
  if (k != a[i][j]) f = 0;
  return;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m;
  for (long long i = 0; i <= n + 1; i++)
    for (long long j = 0; j <= m + 1; j++) a[i][j] = 0;
  for (long long i = 1; i <= n; i++)
    for (long long j = 1; j <= m; j++) {
      char x;
      cin >> x;
      if (x == '*')
        a[i][j] = -1;
      else if (x == '.')
        a[i][j] = 0;
      else
        a[i][j] = x - '0';
    }
  for (long long i = 1; i <= n; i++)
    for (long long j = 1; j <= m; j++) {
      if (a[i][j] == 0)
        chnull(i, j);
      else if (a[i][j] != -1)
        chdef(i, j);
    }
  if (f)
    cout << "YES" << endl;
  else
    cout << "NO" << endl;
  getchar();
  getchar();
  return 0;
}
