#include <bits/stdc++.h>
using namespace std;
int main() {
  int i, j, n, m, flag = 0, cnt = 0, temp;
  cin >> n >> m;
  char a[108][106];
  for (i = 0; i < n; i++) {
    cin >> a[i];
  }
  for (i = 0; i < n; i++) {
    for (j = 0; j < m; j++) {
      cnt = 0;
      if (a[i][j] == '.') {
        if (a[i - 1][j] == '*' || a[i - 1][j - 1] == '*' ||
            a[i][j - 1] == '*' || a[i + 1][j] == '*' || a[i][j + 1] == '*' ||
            a[i + 1][j + 1] == '*' || a[i - 1][j + 1] == '*' ||
            a[i + 1][j - 1] == '*')
          flag = 1;
      } else if (a[i][j] == '*')
        continue;
      else {
        if (a[i - 1][j] == '*') cnt++;
        if (a[i - 1][j - 1] == '*') cnt++;
        if (a[i][j - 1] == '*') cnt++;
        if (a[i + 1][j] == '*') cnt++;
        if (a[i + 1][j + 1] == '*') cnt++;
        if (a[i][j + 1] == '*') cnt++;
        if (a[i - 1][j + 1] == '*') cnt++;
        if (a[i + 1][j - 1] == '*') cnt++;
        temp = (int)(a[i][j] - '0');
        if (cnt != temp) flag = 1;
      }
    }
  }
  if (flag == 1)
    cout << "NO";
  else
    cout << "YES";
}
