#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 10;
const long long INF = 1e18 + 1;
const int MOD = 1e9 + 7;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  ;
  int n, m;
  cin >> n >> m;
  char a[101][101];
  for (int i = 0; i < (n); i++)
    for (int j = 0; j < (m); j++) cin >> a[i][j];
  for (int i = 0; i < (n); i++)
    for (int j = 0; j < (m); j++) {
      if (a[i][j] == '*') continue;
      int bombs = a[i][j] - '0';
      if (a[i][j] == '.') bombs = 0;
      int cnt = 0;
      for (int y = max(0, i - 1); y <= min(n - 1, i + 1); y++)
        for (int x = max(0, j - 1); x <= min(m - 1, j + 1); x++) {
          if (a[y][x] == '*') cnt++;
        }
      if (cnt != bombs) {
        cout << "NO";
        return 0;
      }
    }
  cout << "YES";
  cerr << endl
       << endl
       << "Time execute: " << (float)clock() / CLOCKS_PER_SEC << endl;
  return 0;
}
