#include <bits/stdc++.h>
using namespace std;
int n, m, a[110][110];
string mp[110];
int main() {
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    cin >> mp[i];
  }
  bool res = true;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (mp[i][j] != '*' && mp[i][j] != '.') {
        int val = mp[i][j] - '0';
        int cval = 0;
        for (int k = -1; k <= 1; k++) {
          for (int z = -1; z <= 1; z++) {
            if (k != 0 || z != 0) {
              int i1 = i + k, j1 = j + z;
              if (i1 >= 0 && i1 < n && j1 >= 0 && j1 < m && mp[i1][j1] == '*') {
                cval++;
              }
            }
          }
        }
        if (cval != val) {
          res = false;
          break;
        }
      }
    }
    if (!res) break;
  }
  if (res) {
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        if (mp[i][j] == '.') {
          for (int k = -1; k <= 1; k++) {
            for (int z = -1; z <= 1; z++) {
              if (k != 0 || z != 0) {
                int i1 = i + k, j1 = j + z;
                if (i1 >= 0 && i1 < n && j1 >= 0 && j1 < m &&
                    mp[i1][j1] == '*') {
                  res = false;
                  break;
                }
              }
            }
            if (!res) break;
          }
        }
      }
      if (!res) break;
    }
  }
  if (res)
    cout << "YES";
  else
    cout << "NO";
  return 0;
}
