#include <bits/stdc++.h>
using namespace std;
const int N = (1e6) + 500;
const int MOD = 1e9 + 7;
const long long int BIG = 1e12;
int n;
char a[5000][5000];
int i, j, k, m;
bool isval(int i, int j, int i1, int j1) {
  return ((i + i1 >= 0) && (i + i1 < n)) && ((j + j1 >= 0) && (j + j1 < m));
}
int main() {
  ios_base::sync_with_stdio(false);
  cin >> n >> m;
  for (i = 0; i < n; i++) {
    for (j = 0; j < m; j++) {
      cin >> a[i][j];
    }
  }
  bool flag = true;
  for (i = 0; i < n; i++) {
    for (j = 0; j < m; j++) {
      if (int(a[i][j]) - int('0') <= int('8') - int('0') &&
          int(a[i][j]) - int('0') >= int('1') - int('0')) {
        int numbomb = 0;
        int i1, j1;
        for (i1 = -1; i1 <= 1; i1++) {
          for (j1 = -1; j1 <= 1; j1++) {
            if (isval(i, j, i1, j1) && a[i + i1][j + j1] == '*') numbomb++;
          }
        }
        if (numbomb != int(a[i][j]) - int('0')) {
          flag = false;
        }
      }
      if (a[i][j] == '.') {
        int numbomb = 0;
        int i1, j1;
        for (i1 = -1; i1 <= 1; i1++) {
          for (j1 = -1; j1 <= 1; j1++) {
            if (isval(i, j, i1, j1) && a[i + i1][j + j1] == '*') numbomb++;
          }
        }
        if (numbomb != 0) flag = false;
      }
    }
  }
  if (flag) {
    cout << "YES\n";
  } else {
    cout << "NO\n";
  }
  return 0;
}
