#include <bits/stdc++.h>
using namespace std;
int n, m;
string a[109];
int cnt(int i, int j) {
  int cn = 0;
  if (i + 1 < n && j + 1 < m && a[i + 1][j + 1] == '*') cn++;
  if (i + 1 < n && j - 1 >= 0 && a[i + 1][j - 1] == '*') cn++;
  if (j + 1 < m && a[i][j + 1] == '*') cn++;
  if (j - 1 >= 0 && a[i][j - 1] == '*') cn++;
  if (i - 1 >= 0 && j + 1 < m && a[i - 1][j + 1] == '*') cn++;
  if (i - 1 >= 0 && j - 1 >= 0 && a[i - 1][j - 1] == '*') cn++;
  if (i + 1 < n && a[i + 1][j] == '*') cn++;
  if (i - 1 >= 0 && a[i - 1][j] == '*') cn++;
  return cn;
}
int main() {
  cin >> n >> m;
  for (int i = 0; i < n; i++) cin >> a[i];
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (a[i][j] == '.' && cnt(i, j) != 0) {
        cout << "no";
        return 0;
      }
      if (a[i][j] <= '8' && a[i][j] >= '0' && cnt(i, j) != int(a[i][j] - '0')) {
        cout << "no";
        return 0;
      }
    }
  }
  cout << "yes";
  return 0;
}
