#include <bits/stdc++.h>
using namespace std;
char c[102][102];
int check(int i, int j) {
  for (int l = i - 1; l <= i + 1; l++)
    for (int z = j - 1; z <= j + 1; z++)
      if (c[l][z] == '*') return -1;
  return 0;
}
int check1(int i, int j) { return 0; }
int check2(int i, int j) {
  int a = 0;
  for (int l = i - 1; l <= i + 1; l++)
    for (int z = j - 1; z <= j + 1; z++)
      if (c[l][z] == '*') a++;
  if (a == (c[i][j] - '0')) return 0;
  return -1;
}
string func(int n, int m) {
  int a = 0;
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++) {
      if (c[i][j] == '.')
        a = check(i, j);
      else if (c[i][j] == '*')
        a = check1(i, j);
      else
        a = check2(i, j);
      if (a == -1) return "NO";
    }
  return "YES";
}
int main() {
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < n + 2; i++)
    for (int j = 0; j < n + 2; j++) c[i][j] = '0';
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++) cin >> c[i][j];
  cout << func(n, m);
}
