#include <bits/stdc++.h>
using namespace std;
const int maxn = 101;
char pic[maxn][maxn];
int n, m;
int num = 0;
int dfs(int r, int c) {
  int cnt = 0;
  for (int dr = -1; dr <= 1; dr++) {
    for (int dc = -1; dc <= 1; dc++)
      if (dr != 0 || dc != 0) {
        if (r + dr < 0 || r + dr >= n || c + dc < 0 || c + dc >= m) {
          continue;
        }
        if (pic[r + dr][c + dc] == '*') cnt++;
      }
  }
  if (pic[r][c] == '.' && cnt == 0) return 0;
  if (cnt == int(pic[r][c] - '0')) return 0;
  return 1;
}
int main() {
  cin >> n >> m;
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++) cin >> pic[i][j];
  bool flag = 0;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (pic[i][j] != '*')
        if (dfs(i, j) == 1) {
          flag = 1;
          break;
        }
    }
  }
  if (flag == 1)
    cout << "NO" << endl;
  else
    cout << "YES" << endl;
}
