#include <bits/stdc++.h>
using namespace std;
int n, m, cou;
char c[101][101];
bool b;
int main() {
  cin >> n >> m;
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++) cin >> c[i][j];
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      cou = 0;
      if (i - 1 >= 0 && j - 1 >= 0 && c[i - 1][j - 1] == '*') cou++;
      if (i - 1 >= 0 && j + 1 < m && c[i - 1][j + 1] == '*') cou++;
      if (i + 1 < n && j - 1 >= 0 && c[i + 1][j - 1] == '*') cou++;
      if (i + 1 < n && j + 1 < m && c[i + 1][j + 1] == '*') cou++;
      if (i + 1 < n && c[i + 1][j] == '*') cou++;
      if (j + 1 < m && c[i][j + 1] == '*') cou++;
      if (i - 1 >= 0 && c[i - 1][j] == '*') cou++;
      if (j - 1 >= 0 && c[i][j - 1] == '*') cou++;
      if (c[i][j] != '*') {
        if ((cou == 0 && c[i][j] == '.') || (cou == c[i][j] - '0'))
          ;
        else
          b = 1;
        if (b) break;
      }
    }
    if (b) break;
  }
  if (b)
    cout << "NO";
  else
    cout << "YES";
}
