#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, k;
  cin >> n >> k;
  char a[n + 10][k + 10];
  for (int i = 0; i <= n + 1; ++i)
    for (int j = 0; j <= k + 1; ++j) a[i][j] = '.';
  for (int i = 1; i <= n; ++i)
    for (int j = 1; j <= k; ++j) {
      cin >> a[i][j];
    }
  for (int i = 1; i <= n; ++i)
    for (int j = 1; j <= k; ++j) {
      if (a[i][j] == '*') continue;
      int b = 0;
      if (a[i - 1][j - 1] == '*') b++;
      if (a[i - 1][j] == '*') b++;
      if (a[i - 1][j + 1] == '*') b++;
      if (a[i][j - 1] == '*') b++;
      if (a[i][j + 1] == '*') b++;
      if (a[i + 1][j - 1] == '*') b++;
      if (a[i + 1][j] == '*') b++;
      if (a[i + 1][j + 1] == '*') b++;
      if (b == 0) {
        if (a[i][j] != '.') {
          cout << "no";
          return 0;
        }
      } else if (b != a[i][j] - '0') {
        cout << "no";
        return 0;
      }
    }
  cout << "Yes";
  return 0;
}
